2012-01-31 15 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請求正在觸發與空白response.please幫助。看來GET沒有返回任何東西每螢火蟲的GET請求被火與空白響應

+2

請發佈GET請求和響應從螢火蟲。 – ciphor 2012-01-31 07:34:43

+0

是請求200的響應代碼還是別的?如果請求中發生錯誤,則不會調用該函數。 – Corbin 2012-01-31 07:34:45

回答

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/ (它是一種安全的)

現在,在你的PHP文件,確保您所期望的ID,而不是SID爲你的jQuery函數:

<?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語句,你會收到一個空白頁(也空響應),你可以檢查它開放「的國家.php'直接在瀏覽器中。

問候。