点击按钮 - 调用Ajax函数
问题描述:
我卡住了。我尝试通过按钮单击来进行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);
}
});
};
答
你也可以,如果你正在使用jQuery使用此方法:
$("button").click(function(){
$.get("load_info.php",
{
id: id_number
},
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
我很抱歉,但这个按钮是在谷歌地图infoWindow。并在“即时”生成。我需要通过我的例子找到解决方案。 – Patrik