我有一个按钮,当按下时调用jQuery $ .get()并且它应该返回一个值并放入一个输入字段(文本框)但它永远不会被调用。我做错了什么?..
$(document).ready(function() {
$('button#getbasedomain').click(function() {
var contentSource = $.trim($('input#contentsource').val());
if (contentSource == '') {
alert('No Content Source entered.');
return false; // THIS GETS CALLED, WORKS FINE WHEN SOURCE IS EMPTY
} else {
$.get('admin/getbasedomain.php?id=' + contentSource, function(result) {
$('input#basedomain').val(result);
alert('$.get was run. Result = ' + result ); // THIS NEVER GETS CALLED.
});
return false;
}
});
});
答案 0 :(得分:0)
我希望回复404或50x :)
。尝试在get请求中添加.fail()
链。我希望你的php脚本出错,或者它找不到php脚本。
$.get('admin/getbasedomain.php?id=' + contentSource, function(result) {
$('input#basedomain').val(result);
alert('$.get was run. Result = ' + result ); // THIS NEVER GETS CALLED.
}).fail(function(e){
alert("OH NO something went wrong.. what could it be...");
});
检查浏览器控制台中的网络选项卡,查看请求是否被触发以及响应代码是什么