I just started using php&ajax so sevenspark i’m i doing it the right way 
- Sold between 250 000 and 1 000 000 dollars
- Community Moderator
- Author was Featured
- Item was Featured
- Bought between 50 and 99 items
- Referred between 1000 and 1999 users
- Has been a member for 3-4 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
iGhost said
I just started using php&ajax so sevenspark i’m i doing it the right way![]()
Hey iGhost, yup, your code looks good to me – definitely the right strategy. I think jQuery is the easiest way to go as well – it greatly simplifies the AJAX process. I’d make 2 minor suggestions:
1. This line has some errors (probably just simple typos):if(respons.success = 1) {
should be
if(response.success == 1) {
2. After echoing in the PHP , you should probably include die() so that the PHP doesn’t write any additional lines (like whitespace after the closing PHP tag) back to the browser, which can create json or headers errors.
Of course, you’ll also need to attach the AJAX function to a submit event, something like:
$('form').submit(function(){
//do your ajax here
return false;
});
It would also be good to include fallback functionality for graceful degradation when JS is disabled. The form could submit hidden elements for action and id. The jQuery could submit an extra data value that indicates that AJAX is being used. This value could be checked server-side to determine whether the server should respond with JSON or not. Obviously the details are specific to the implementation here, but that’s something else to keep in mind.
Also, you can use $.getJSON in many cases, which simplified the ajax call. See http://api.jquery.com/jQuery.getJSON/
Hope that helps 
Ya i tried to edit my posts to fix those typing errors but it wouldn’t work
i also forgot that return false 
Thanks for the heads up 
iGhost said
Hey Ruben you might wanna do something like this:PHP code<?php if(isset($_POST['go']){ // button name do_stuff(); }else{ do_other_stuff(); } ?>Hope that’s what you want
How could that work? The second bracket of the if() statement isn’t there, so it would throw an error. 
- Most Wanted Bounty Winner
- Sold between 250 000 and 1 000 000 dollars
- Has been a member for 5-6 years
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Won a Competition
- Bought between 100 and 499 items
- Exclusive Author
- Referred between 200 and 499 users
jQuery.get('add_xml.php?id='+xml_count, function(data){
//stuff here
});
Thanks for your replies guys! 
