2016-12-06 107 views
0

我卡住了。我嘗試通過按鈕單擊來進行Ajax調用。函數正在加載和響應HTML數據。 HTML格式的數據如「< div> ... </div>」。當我在瀏覽器中打開「http://domain.com/load_info.php?id=1」時,我得到所有的HTML數據。但是當我嘗試通過Ajax函數加載它時,沒有任何內容正在加載。點擊按鈕 - 調用Ajax函數

按鈕

<input type='button' onclick='getInfo(1);' value='Load Info' > 

的Ajax功能

function getInfo(id_number){ 
     alert('function started with id =' + in_number); // this alert works fine 
     $.ajax({ 
      type:"GET", 
      data: { 'id': id_number }, 
      url : "load_info.php", 
      dataType: "text", 
      success: function(response) { 
       alert('success');     // this alert is not working 
       $("#info").prepend(response); 
      } 
     }); 
    }; 

回答

1

你也可以,如果你正在使用jQuery使用此方法:

$("button").click(function(){ 
    $.get("load_info.php", 
    { 
     id: id_number 
    }, 
    function(data, status){ 
     alert("Data: " + data + "\nStatus: " + status); 
    }); 
}); 
+0

我很抱歉,但這個按鈕是在谷歌地圖infoWindow。並在「即時」生成。我需要通過我的例子找到解決方案。 – Patrik