[eluser]stoefln[/eluser]
hi,
i m calling a method "deleteImages" by ajax in one of my controllers.
after deleting the images i want to return a refreshed view of the list of images.
now i have the problem that the method "deleteImages" can be called from different locations (different views). how can i determine where the ajax call was made from and what view therefore should be chosen?
[eluser]pistolPete[/eluser]
You can send an additional parameter in your ajax call containing the current "location".
[eluser]stoefln[/eluser]
maybe my question is not as complete as it should. determining the location is acutally not a big problem: i can call $this->uri->segment(3) to get the method where the current view was rendered. but i have to do a switch($this->uri->segment(3)), that means i have to do a manually routing of methods and parameters. thats something what CI usually does for me. isnt there a more generic way, maybee using the routing functionallity of CI?
[eluser]pistolPete[/eluser]
Could you please provide some example code of your controller and view?
What needs to be different in the response to the ajax call?
What parameters do your ajax requests contain?
[eluser]stoefln[/eluser]
Yeah, but the methods have different parameter sets- so i would need a switch in this case too... another issue is that the user could call EVERY method in the controller
[eluser]TheFuzzy0ne[/eluser]
Not if you're running PHP 5 and you make the private methods. Or in fact, probably better yet, prefix the functions with an underscore if you don't want them directly accessible from the outside.
[eluser]pistolPete[/eluser]
Another thought:
Why do you have to respond with the updated image list?
You could only respond with (e.g.) a JSON "true"/"false" success message, then the ajax script would react and reload the image list by directly calling the appropriate controller function.