I have this code:
var data_string = $('form#frm').serialize();
$.ajax({
type: "POST",
url: "/send.php",
data: data_string,
success: function(data) {
alert(data);
And in the php file:
$to = mysql_real_escape_string($_POST['email']); //email
$name = mysql_real_escape_string($_POST['name']); //name of tipper
$msg = mysql_real_escape_string($_POST['msg']); //message
echo $name; //EXAMPLE
The above alert in the ajax code SHOULD alert the posted $name variable.
However, the alertbox comes up, but it is blank.
I think it has to do with the serialize part.
echoing 1 or 0 from php works fine, and the alert box shows the 1 or 0.
Any ideas whats wrong?
Thanks
EDIT:
Found out that when alerting the serialized data:
alert (data_string);
I get “undefined”…
And here is the form:
<form name='frm' id='frm' action='send.php' method='post' onsubmit='tip_func(); return false;'>
<input type='text' name='name' id='name'>
tip_func() is the function where all the above ajax is…
Have you tested the
data_string? Try doing an alert on it first to check it has data in it!