0

在这个文件中这样调用:

/fichier_clients/fiche_client.html?id=4870

它使用“id”值并向外部文件(php)发出请求。数据不会传递到 php 文件(外部域)。远程 php 文件执行良好,没有错误并重新发送提取。来自具有测试 id的数据库的数据,但不是通过 ajax -> params: {"term": id} 接收的值,

  <link href="jquery-mobile/jquery.mobile.theme-1.0.min.css" rel="stylesheet" type="text/css"/>
  <link href="jquery-mobile/jquery.mobile.structure-1.0.min.css" rel="stylesheet" type="text/css"/>
  <script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
  <script src="jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
  <script type='text/javascript' language='javascript'>
  function fiche0()
  {
      var id = location.search; 
      var id = id.split('='); 
      var id = id[1];   
      alert (id);
      var encoded = encodeURIComponent('http://www.mydomain.fr/connexion.php');

      $.ajax({
    url: 'http://whateverorigin.org/get?url='+encoded,
    type:'POST',
    contentType:"application/json",
    dataType: 'jsonp',
    crossDomain:true,
    params: {"term": id},
    timeout: 4000
    }).done(function(reponse){
         a=reponse.contents.split(';'); 
              document.getElementById("client").innerHTML = a[0] ;
              document.getElementById("adresse1").innerHTML = a[1] ;
      })


  }


  window.onload = fiche;
  </script>
4

2 回答 2

0

您不能 POST 到外部域,只有 GET 请求将数据传递到外部。

我建议在您的 php 脚本中使用 $_REQUEST 而不是 $_POST,这样您就可以看到所有数据,无论它是如何发送的。

于 2013-10-31T14:54:58.430 回答
0

在这种情况下,我可以发送数据,但没有返回


  <script type="text/javascript">
  function get_XmlHttp() {
    // create the variable that will contain the instance of the XMLHttpRequest object (initially with null value)
    var xmlHttp = null;
    if(window.XMLHttpRequest) {        // for Forefox, IE7+, Opera, Safari, ...
      xmlHttp = new XMLHttpRequest();
    }
    else if(window.ActiveXObject) {    // for Internet Explorer 5 or 6
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttp;
  }
  // sends data to a php file, via GET, and displays the received answer
  function ajaxrequest(pid) {
    var request =  get_XmlHttp();        // call the function for the XMLHttpRequest instance

    // create the URL with data that will be sent to the server (a pair index=value)
    var  url = 'http://www.mydomain.fr/connexion.php?term=3334';

    request.open("GET", url, true);            // define the request
    request.send(null);        // sends data

    // Check request status
    // If the response is received completely, will be transferred to the HTML tag with tagID
    request.onreadystatechange = function() {
      if (request.readyState == 4) {
          alert ("toto");
        document.getElementById("context").innerHTML = request.responseText;
      }
    }
  }


    window.onload = ajaxrequest;
  </script>

  <div id="context"></div> 
于 2013-11-02T01:01:38.810 回答