kirill578 Posted February 18, 2011 Share Posted February 18, 2011 This code doesn't work/execute anything ( ajax_request.php works fine) $.post("ajax_request.php", { vote: "a", id: "2", category: "0" }, function(data) { $("div#result_a_show").text("" + data.a); $("div#result_b_show").text("" + data.b); $('a#next_link').attr('href', data.link); }, "json"); Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/ Share on other sites More sharing options...
RichardRotterdam Posted February 18, 2011 Share Posted February 18, 2011 I think you're using the function incorrect. Try something like: $.post({ url: 'yoururlhere.php', data: {data: 'here'} dataType: 'json', success: function(data) { // do stuff here when the data returns } }); Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1176213 Share on other sites More sharing options...
kirill578 Posted February 19, 2011 Author Share Posted February 19, 2011 i tried this. but now all the code doesn't working. $.post({ url: 'ajax_request.php', data: { vote: 'b', id: '2', category: '0' } dataType: 'json', success: function(data) { $("div#result_a_show").text("" + data.a); $("div#result_b_show").text("" + data.b); $('a#next_link').attr('href', data.link); } }); Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1176630 Share on other sites More sharing options...
RichardRotterdam Posted February 19, 2011 Share Posted February 19, 2011 you forgot a comma after the data line data: { vote: 'b', id: '2', category: '0' },// comma here Have you got something like firebug it's a lot easier to see what you have done wrong if you get some sort off error feedback Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1176631 Share on other sites More sharing options...
kirill578 Posted February 19, 2011 Author Share Posted February 19, 2011 Now i have the same problem, it doesn't execute anything Can you look at the code here? http://maadif.co.cc/ajax/prefer/index.php Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1176649 Share on other sites More sharing options...
RichardRotterdam Posted February 19, 2011 Share Posted February 19, 2011 It does do something it doesn't find the url. It's because jQuery.post() and jQuery.ajax() work differently. Use firebug to see what's going on. If you change $.post to $.ajax and add type:'post as parameter it should prob work. $.ajax({ type:'post' }); Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1176741 Share on other sites More sharing options...
kirill578 Posted February 19, 2011 Author Share Posted February 19, 2011 I downloaded FireBug. Is says that the POST send successful and it gets the right response but the problem has I already said before is that it doesn't execute the success function. I tried to add alert into it but i doesn't apper as well. ( My feeling that jQuery hates me :'( ) Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1176828 Share on other sites More sharing options...
RichardRotterdam Posted February 19, 2011 Share Posted February 19, 2011 What I suggested works fine for me. what does your code look like now? Edit I took a look at the link and noticed the change try a console.log and see if something happens. or do a alert('some text') that way you'll be sure the function runs Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1176857 Share on other sites More sharing options...
kirill578 Posted February 20, 2011 Author Share Posted February 20, 2011 That is exactly what I did. Just look at the code here http://maadif.co.cc/ajax/prefer/index.php Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1177241 Share on other sites More sharing options...
kirill578 Posted February 21, 2011 Author Share Posted February 21, 2011 I have finally found out that the problem is the PHP file its output starts in the third line.. Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1177821 Share on other sites More sharing options...
cssfreakie Posted February 22, 2011 Share Posted February 22, 2011 I have finally found out that the problem is the PHP file its output starts in the third line.. could you maybe show what you mean by that, and what was the solution. sorry for asking but i am pretty eager to learn this Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1178041 Share on other sites More sharing options...
haku Posted February 22, 2011 Share Posted February 22, 2011 It probably means that the output file was printing three linebreaks before executing it's code. Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1178163 Share on other sites More sharing options...
cssfreakie Posted February 22, 2011 Share Posted February 22, 2011 It probably means that the output file was printing three linebreaks before executing it's code. ok cool thanks! haku Quote Link to comment https://forums.phpfreaks.com/topic/228087-jquery-ajax-post-problem/#findComment-1178298 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.