views:

52

answers:

3

I have a very simple jQuery script.. all I want it to do is return the data on the PHP/HTML page but it's not working. The code is below:

function sendData() {

$.post("validation.php", $("#c_form").serialize(), function(data){}, "html");

}

The function is called by an onclick event in the form. I don't get why it is isn't working, very stumped. Any ideas? There are no errors that pop up in the firefox console window.

A: 

Try:

$.post("validation.php", $("#c_form").serialize(), function(data){
    alert(data);
}, "html");

I take it the reason you're not seeing anything is because you're not doing anything when the result comes back from the server. If the data expected back from the server is html, you can safely omit the last optional parameter:

$.post("validation.php", $("#c_form").serialize(), function(data){
    alert(data);
});
karim79
A: 

Also don't forget about returning false at the end of your click event:

$("button").click(function(){
      sendData();
      return false;
});
Juraj Blahunka
A: 

Thanks everyone :) karim79's code made me realized my error. After trying his code I noticed it returned the result fine in the alert. So the problem was that I did not specify a DIV to output the information in. I figured it would just print the information in the main body, but was wrong on that.

mike