1

我正在加载页面 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>
4

2 回答 2

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();
                         }
                       }
                             );

                 }
于 2013-10-19T07:45:02.987 回答
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();
    }
});
于 2013-10-19T08:57:22.887 回答