jQuery的$。员额空数组 [英] jquery $.post empty array

查看:191
本文介绍了jQuery的$。员额空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery来发布形式的PHP文件,简单的脚本来验证用户的详细信息。

I'm using jQuery to post a form to a php file, simple script to verify user details.

var emailval = $("#email").val();
var invoiceIdval = $("#invoiceId").val();

$.post("includes/verify.php", 
       {invoiceId:invoiceIdval , email:emailval },
       function(data) { 
          //stuff here.
});

PHP code:

PHP Code:

<?php
print_r($_POST);
?>

我看看萤火的反应,这是一个空数组。阵列应具有至少一些值

I look at the response in firebug, it is an empty array. The array should have at least some value.

我想不通,为什么 $ _ POST 不工作的PHP文件。萤火虫显示帖子包含的内容发布,电子邮件,发票编号,只是没有什么实际上是在PHP文件收到的。

I can not work out why the $_POST isn't working in the php file. Firebug shows the post to contain the contents posted, email and invoice id, just nothing is actually received in the php file.

形式:

<form method="post" action="<?=$_SERVER['PHP_SELF']; ?>" enctype="application/x-www-form-urlencoded">

任何人都知道它在做什么?

Anyone know what its doing?

感谢

发现这个 - http://www.bradino.com/php/empty-后阵列/

这是一个明智的路线走?

that a sensible route to go?

推荐答案

$。员额()将数据传递到底层 $。阿贾克斯( )通话,这台应用程序/ x-WWW的形式urlen codeD 默认情况下,所以我不认为这是。

$.post() passes data to the underlying $.ajax() call, which sets application/x-www-form-urlencoded by default, so i don't think it's that.

您可以试试这个:

var post = $('#myForm').serialize();    

$.post("includes/verify.php", post, function(data) { 
    alert(data);
});

连载()通话将抢在 form.myForm 目前所有的数据。

the serialize() call will grab all the current data in form.myForm.

这篇关于jQuery的$。员额空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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