Javascript 无法在jQuery方法中使用alert()
使用jQuery进行AJAX调用时,目前我只希望有一个弹出框(使用Javascript 无法在jQuery方法中使用alert(),javascript,jquery,ajax,alert,Javascript,Jquery,Ajax,Alert,使用jQuery进行AJAX调用时,目前我只希望有一个弹出框(使用alert())显示响应文本 $(document).ready(function() { $(".jeobutton").mouseup(function() { var $button = $(this); $.ajax({ url: 'getdata.php', data: // <parameters> type: 'get
alert()
)显示响应文本
$(document).ready(function() {
$(".jeobutton").mouseup(function() {
var $button = $(this);
$.ajax({ url: 'getdata.php',
data: // <parameters>
type: 'get',
dataType: 'json',
success: function(output) {
// do something
},
error: function(xhr) {
alert("<some error>");
console.error(xhr.responseText);
}
});
});
});
$(文档).ready(函数(){
$(“.jeobutton”).mouseup(函数(){
var$按钮=$(此按钮);
$.ajax({url:'getdata.php',
数据://
键入:“get”,
数据类型:“json”,
成功:功能(输出){
//做点什么
},
错误:函数(xhr){
警报(“”);
控制台错误(xhr.responseText);
}
});
});
});
响应文本打印得很好。但是,找不到alert()
对话框
请帮助这个可怜的家伙。这是一个JSFIDLE,它与您的代码非常接近,如果正常工作,就会弹出警报框
$(文档).ready(函数(){
$(“.jeobutton”).mouseup(函数(){
控制台日志(“单击”);
var$按钮=$(此按钮);
$.ajax({url:'getdata.php',
键入:“get”,
数据类型:“json”,
成功:功能(输出){
控制台日志(“成功”);
},
错误:函数(xhr){
警报(“”);
控制台错误(xhr.responseText);
}
});
});
});
清除浏览器缓存。可能会有不显示更多警报的选项。
在不同的浏览器中测试
我希望这会有帮助。console.log(alert.toString())显示了什么?
函数alert(){[native code]}
我将您的代码放入了JSFIDLE,它成功了。我确实删除了“data:”行,因为它缺少一个逗号。我可以有一个指向上述fiddle的链接吗?您的解决方案确实在JSFIDLE中有效,但我仍然没有在本地服务器上获得对话框。非常奇怪。您在本地使用的jQuery版本是什么?还有什么浏览器?我通过Google的CDN在这个链接上使用jQuery 1.9.1://ajax.googleapis.com/ajax/libs/jQuery/1/jQuery.min.js
和Google Chrome在基本操作系统Luna上。您的控制台中有任何错误吗?其他地方的语法错误可能会导致这种行为。JS控制台中唯一的错误是我通过console.error()
登录的错误。我猜@thatJavaNerd去年已经清除了浏览器缓存。请看问题的日期!
$(document).ready(function() {
$(".jeobutton").mouseup(function() {
console.log("clicked");
var $button = $(this);
$.ajax({ url: 'getdata.php',
type: 'get',
dataType: 'json',
success: function(output) {
console.log("success");
},
error: function(xhr) {
alert("<some error>");
console.error(xhr.responseText);
}
});
});
});