我有这个code:
var data_string = $('form#frm').serialize();
$.ajax({
type: "POST",
url: "/send.php",
data: data_string,
success: function(data) {
alert(data);
而在PHP文件:
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
在阿贾克斯code上面的警告应该警惕公布 $名称
变量。
然而,alertbox出现,但它是空白的。
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.
呼应1或0从PHP工作正常,以及警报框显示的1或0。
echoing 1 or 0 from php works fine, and the alert box shows the 1 or 0.
任何想法什么错?
感谢
编辑:
发现,提醒序列数据时:
Found out that when alerting the serialized data:
alert (data_string);
我得到未定义......
I get "undefined"...
和这里的形式是:
<form name='frm' id='frm' action='send.php' method='post' onsubmit='tip_func(); return false;'>
<input type='text' name='name' id='name'>
tip_func()的函数,其中所有上述Ajax是...
tip_func() is the function where all the above ajax is...
你测试了 data_string
?尝试在其上做一个警报首先要检查它的数据呢!
Have you tested the data_string
? Try doing an alert on it first to check it has data in it!
var data_string = $('#frm').serialize();
alert(data_string);