简体   繁体   English

序列化的Ajax参数未在PHP中显示

[英]Serialized Ajax Parameters not showing up in PHP

I am trying to access the parameters passed in my AJAX request, but when I try to print them out in PHP, nothing shows up. 我正在尝试访问在AJAX请求中传递的参数,但是当我尝试在PHP中将其打印出来时,什么都没有显示。 I know emailData is defined and correct, so that is not the problem. 我知道emailData已定义且正确,所以这不是问题。

Here is my current code: 这是我当前的代码:

function sendEmail(){
var emailData = $('emailForm').serialize(true);
new Ajax.Request("php/email.php",
    {
        method : "get",
        parameters : emailData,
        onFailure : ajaxFailure,
        onException : ajaxFailure
    }
);}

and in email.php 并在email.php中

print_r($_GET);

EDIT 编辑

When I check to see if emailData is defined with an alert or console.log, I get the correct values I want, in the correct format for ajax parameters according to http://www.prototypejs.org/api/form/serialize . 当我检查是否用alert或console.log定义了emailData时,会根据http://www.prototypejs.org/api/form/serialize以ajax参数的正确格式获取所需的正确值。

2nd EDIT 第二次编辑

Seems to work now. 似乎现在可以工作。 I haven't modified the code at all, but it seems to work now. 我根本没有修改代码,但现在似乎可以正常工作了。

You have no onSuccess: value. 您没有onSuccess:值。 You're only checking for errors and exceptions. 您仅在检查错误和异常。

Do something like: 做类似的事情:

function sendEmail(){
var emailData = $('emailForm').serialize(true);
new Ajax.Request("php/email.php",
    {
        method : "get",
        parameters : emailData,
        onFailure : ajaxFailure,
        onException : ajaxFailure,
        onSuccess : function() { alert("success!"); }
    }
);}
var emailData = $('#emailForm').serialize(true);

emailform可能是一个id?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM