[英]jquery not sending parameters to php
I am running into an issue where jquery is not sending parameters at all. 我遇到一个问题,其中jquery根本不发送参数。 I looped through the $_POST and $_REQUEST and neither one contained my information.
我遍历了$ _POST和$ _REQUEST,但没有一个包含我的信息。
//jquery client side
$.post(http://www.example.com/myscript.php,{"data":"1234"})
.done(function(info){alert("returned data "+info);});
//myscript.php server side
<?php
foreach($_POST as $val){
echo $val;
}
?>
i have also tried $_REQUEST, I've tried $.get. 我也尝试过$ _REQUEST,我尝试过$ .get。 I dont know what I'm doing wrong.
我不知道我在做什么错。 If I call the php code in the url bar ( http://www.example.com/myscript.php?data=1234 ) when it uses $_REQUEST it works.
如果我在使用$ _REQUEST时在网址栏中调用php代码( http://www.example.com/myscript.php?data=1234 ),则它可以工作。 I tried putting the url in quotes and that didn't work, I tried taking the 1234 out of the quotes and that didn't work.
我尝试将URL放在引号中,但没有用,我尝试从引号中取出1234,但没有用。 I have looked through just about every jquery question on SO and didn't find something that works but I may have missed something.
我已经遍历了关于SO的每个jquery问题,但没有找到任何可行的方法,但我可能错过了一些方法。 Any help is appreciate.
任何帮助表示赞赏。
//jquery client side // jquery客户端
// missing quotes around url //网址附近缺少引号
$.post("http://www.example.com/myscript.php",{"data","1234"})
.done(function(info){alert("returned data "+info);});
Can you try using this, 你可以尝试使用这个吗
$.post( "http://www.example.com/myscript.php", { data: "1234"} ).done(function( info ) {
alert("returned data "+info);
});
Ref: http://api.jquery.com/jQuery.post/ 参考: http : //api.jquery.com/jQuery.post/
JavaScript中有{“ data”,“ 1234”},正确的是:
{"data":"1234"}
I'd like to suggest an alternative if I may... 如果可以的话,我想提出一个替代方案。
$.ajax({
type: 'POST',
url: 'http://www.example.com/myscript.php',
data: { data: "1234" },
success: function doAfterPost() {
// do this after the post has been sent
}
});
This should send $_POST["data"]
to the specified php file with a string value of 1234
. 这应该将
$_POST["data"]
发送到字符串值为1234
的指定php文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.