I’m trying to process a form with php via the jquery post function. The first part, with serializing the data is working. I’m alerting out the data and everything looks good. But I’m not getting a response back from php. To debug this I have tried just simply echoing back a text message and that is not even working. What am I doing wrong?
Here is my query:
$(document).ready(function(){
$(".vote_btn").click(function() {
var formData = $('#form').serialize();
alert(formData); // this is alerting the correct info
$.post('scripts/proc_form2.php', formData, processResponse);
});
function processResponse(data){
alert(data); // the alert never triggers
}
}); // end doc.ready
Is the URL okay? Depending on where you are on the website, you might have to change the URL of your script to [color=red]/[/color]scripts/proc_form2.php
Also, take a look at the Net(work) panel in Firebug / Chrome Development Tools to see what’s happening with the request (request headers, response headers, etc).
I tried both with and without the ‘/’ in front of scripts. The php file is in a script folder. The script folder is at the same level as the index file with the form. I think the path should be ok though because I can use the same path in the forms action attribute and the php runs.
I’m not really sure what to look for in the network panel. I really only use the elements and console panels. I see a post method with status 200 / ok is that what you mean?
That’s what I meant, yes. So that part seems to be okay as well. To be honest, I’m kinda stumped. The only think I can think of is that normally you don’t pass a function identifier but an anonymous function to $.post. I don’t think it’ll matter, but for arguments sake could you try the following?
$(document).ready(function() {
$(".vote_btn").click(function() {
var formData = $('#form').serialize();
alert(formData); // this is alerting the correct info
$.post('scripts/proc_form2.php', formData, function(data) {
alert(data); // the alert never triggers
});
});
});
No worries. I ended up not using query to process the form. I am still curious as to why though. But no need to spend any more time on my part. Thanks for your efforts though.