Ajax newbie - nothing happening |
[eluser]richzilla[/eluser]
Hi All, Ive never really looked at ajax much before, JS is not my strong point, and im having a bit of trouble with this function: Code: var user_data = And the method in my code: Code: function ajax() Nothing happens when i call it with javascript, and im not entirely sure where to start looking. The function works when i call it normally (without using JS). Whats the best format to return the data from the server in? any help would be appreciated.
[eluser]philm[/eluser]
I find it really useful to use Firefox with a couple of addons to trouble shoot these types of things. https://addons.mozilla.org/en-US/firefox/addon/60 With this one, once installed you'll have an extra toolbar with all kinds of cool toys in it. On the far right there are 3 little icons which flag errors in HTML, CSS and JAVASCRIPT. Click on the little JS icon and it will open a popup and show you the error, nice and easy http://getfirebug.com/ Here you can track and trace all ajax calls under the 'Console' tab. Hope this helps...
[eluser]nelson.wells[/eluser]
Without looking too much at it, your php function should be echoing the data, not returning it. What I like to do is put data into an associative array, json_encode it, and then 'return' it to the calling js function and output like you are doing in js. Code: $data = array(
[eluser]danmontgomery[/eluser]
[quote author="philm" date="1271348488"]I find it really useful to use Firefox with a couple of addons to trouble shoot these types of things. https://addons.mozilla.org/en-US/firefox/addon/60 With this one, once installed you'll have an extra toolbar with all kinds of cool toys in it. On the far right there are 3 little icons which flag errors in HTML, CSS and JAVASCRIPT. Click on the little JS icon and it will open a popup and show you the error, nice and easy http://getfirebug.com/ Here you can track and trace all ajax calls under the 'Console' tab. Hope this helps...[/quote] Seconding this post... these two addons are essential and everyone should have them. |
Welcome Guest, Not a member yet? Register Sign In |