Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Controller with Ajax Request
#1

Hi guys,

I implemented in my Controller a function to set the data in session; if the session is set in my View show some information. The code works but I do not like the page refresh so I used a js with that call my function in Controller and show the information with slide effect. The problem is that the Controller set session but the slide effect is not works!

You have any solution or example ?

Thanks
Reply
#2

Someone might be able to help you troubleshoot the problem if you include the code you are using to attempt to do this. If the data is updating properly on the view via AJAX and you just aren't getting the visual effect you want, it's really just a matter of troubleshooting the JavaScript which invokes the slide.
Reply
#3

My general tips (may not be the best, but this is what I usually do):

1) The function in the controller must check if it is an HTTP POST request, using $this->input->post(). You can also check if it is an AJAX request using $this->input->is_ajax_request().
2) The above function will return data in text format - can be html, json or simply plain text. (This will be the response in step 4)
3) JS function you use to execute the controller's function should send HTTP POST, instead of HTTP GET. (I use jQuery .post())
4) The response received from HTTP POST can be processed to can determine whatever action to be done.

Correct me if I'm wrong, I'm still learning.
Reply
#4

(This post was last modified: 01-12-2015, 02:10 PM by bclinton.)

In addition to the hnz's suggestion, I think the #1 absolute first thing one needs to do when working with JavaScript/AJAX is to learn how to use their browsers developer tools (or web console or whatever it's called in your browser of choice).

In Google Chrome, right click on your page and click "inspect element" to open up the Dev Tools (or ctrl-shift-I). Click over to the network tab. This will allow you to examine the requests sent via AJAX and the responses returned from CodeIgniter. There is also a "Console" tab where you can log things from your Javascript code.

Those two things are the very basic uses for the Dev Tools, but they can get you started. There's a lot more in there. When you get familiar with the "Network" and "Console" tabs, check out the "Elements" tab to explore CSS issues and the "Sources" tab for more advanced debugging.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB