阿贾克斯连载;在PHP着“读”变量 [英] Ajax serialize; Cant 'read' variables in PHP

查看:95
本文介绍了阿贾克斯连载;在PHP着“读”变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个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);

这篇关于阿贾克斯连载;在PHP着“读”变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆