2012-01-31 2 views
0
<script> 
    function country_state(sid) { 
     var id = sid; 
     console.log("Function called " + sid + " " + $("#state").val()); 
     $.get("country.php?id=" + id, function(d) { 
      console.log("Function returned " + d); 
      alert("Returned: " + d); 
      $(".media").html(d); 
     }); 

    } 
</script> 

空白応答で火災され、このコードでは第一のエラーログが2nd.ItがGETがあるようだ来ていないがあるがGETは任意のものを返していないようです火かき棒ごとにGET要求が空のresponse.pleaseヘルプで起動しているにもかかわらず、何も返さない。放火犯ごとにGETリクエストが

+2

FirebugからのGETリクエストと応答を投稿してください。 – ciphor

+0

リクエストのレスポンスコードは200か他に何かありますか?リクエストでエラーが発生した場合、その関数は呼び出されません。 – Corbin

答えて

0

あなたはドキュメントを見て、エラーコールバックを試みることができる: http://api.jquery.com/jQuery.get/

// Assign handlers immediately after making the request, 
    // and remember the jqxhr object for this request 
    var jqxhr = $.get("example.php", function() { 
    alert("success"); 
    }) 
    .success(function() { alert("second success"); }) 
    .error(function() { alert("error"); }) 
    .complete(function() { alert("complete"); }); 

    // perform other work here ... 

    // Set another completion function for the request above 
    jqxhr.complete(function(){ alert("second complete"); }); 
0

は、例えば次のようなコードを改善するために試してみてください。

function send(id) { 
      $.get('country.php', { id:id }, function(data) { 
      var secureData = eval('(' + data.split('while(1);')[1] + ')'); 
      if (typeof callback == 'function') callback(secureData); 
      alert(data); 
     }); 
} 

私はすべてのことを使うのはなぜ?これをチェックして、あなたは答えを得るでしょう:今すぐ http://insecureweb.com/javascript/secure-your-ajax-request-with-jquery/ (それはセキュリティのようなものだ)

を、あなたはjQueryの関数としてSID IDを期待していませんあなたのPHPファイルで確認してください:

<?php 
//$_GET['id'] the name of 'id' was defined on jquery $.get { param:param } 
//this is a common mistake (getting confused of what you passed in parameters like for example using ID and SID) 
    if ($_GET && isset($_GET['id'])){ 

    $id = $_GET['id']; 
    //do your work here 

    } 
?> 

これはうまくいくかもしれませんし、PHPのif文を渡さないと空白のページ(空の応答も)を受け取って、それを確認することができます。 .php 'を直接ブラウザに表示します。

よろしくお願いいたします。

関連する問題