我正在加载页面url.php并希望将$ x传递给url.php。
var myid=mydata.id;
$.ajax({
url:'url.php'
,async: true
,cache: false
, data : 'post_field=' + myid
,dataType: 'html'
,success: function(data){
$('body').html(data);
FB.XFBML.parse();
}
}
);
在url.php
<?php
$myid=$_POST[myid];
echo "myID is : <br>";
echo myid;
?>
这里有什么问题?
给予错误:
<br />
<b>Notice</b>: Use of undefined constant myid - assumed 'myid' in <b>/opt/lampp/htdocs/FB/ec2/url.php</b> on line <b>2</b><br />
<br />
<b>Notice</b>: Undefined index: myid in <b>/opt/lampp/htdocs/FB/ec2/url.php</b> on line <b>2</b><br />
myID is : <br><br />
<b>Notice</b>: Use of undefined constant myid - assumed 'myid' in <b>/opt/lampp/htdocs/FB/ec2/url.php</b> on line <b>4</b><br />
myid<html>
答案 0 :(得分:1)
传递帖子值...使用
$.ajax({
url:'url.php'
,async: true
,cache: false
,dataType: 'html'
, data : 'post_field=' + $x
,success: function(data){
$('body').html(data);
FB.XFBML.parse();
}
}
);
}
如果您正在使用jquery并想发布表单输入,则可以执行
var data = $('#my_form').serialize();
$.ajax({
url:'url.php'
,async: true
,cache: false
,dataType: 'html'
, data : data
,success: function(data){
$('body').html(data);
FB.XFBML.parse();
}
}
);
}
答案 1 :(得分:1)
试试这个:
var formData = $('#formId').serialize();
$.ajax({
type: 'POST',
url: 'url.php',
async: true,
data: formData,
cache: false,
success: function(data){
$('body').html(data);
FB.XFBML.parse();
}
});