我已经与这一半的一天或更多的摔跤。我无法弄清楚什么是错的。我剥去了其他的JavaScript函数,php代码等;我仍然会重新加载一个页面,而不是一个没有任何返回的异步调用。 Firebug也不会显示XHR呼叫。jquery - 阿贾克斯调用只是不工作
jquery加载正常,并且对其他功能正常工作。任何Ajax或jSON调用都不能异步工作。
我甚至将按键功能改变为一个简单的按钮点击处理程序和相同的结果......没有。
如果我直接加载“findmatch.php”页面,它会生成正确的结果。
在同一个目录中的另一个程序毫不费力和完美地使用了大量的ajax和jSON调用。相同的doctype,相同版本的jquery,相同的ajax调用结构....我很困惑。我一直在寻找真正愚蠢的错误,因为这些事情往往是......但没有运气。
<script type=text/javascript>
$(document).ready(function() {
$('#searchtext').live('keypress',function(e)
{ if (e.which == 13) {
mysearch=$("#searchtext").val(); if(mysearch=="") {
alert("Trying typing something in the box, ok?"); } else {
$.ajax({
url: 'findmatch.php',
data: 'x='+mysearch,
dataType: 'html',
success: function(res)
{
alert(res);
if(res.length>0)
{
buildit="<table><tr><td>id</td>td><b>Machine Name</b></td></tr>";
buildit=buildit+res+"</table>";
$("#searchresults").html(buildit);
$("$searchtext").focus();
}
else
{
$("#searchresults").html("No Results Found");
$("#searchtext").focus();
}
}
}); }
} });
});
</script>
</head>
<body>
<div class="searchy">
<h3>Search for an existing record?</h3>
<form>
Enter a Machine Name to search for, such as "bl-psy-srv" or "psy-srv" or something similar. A partial name will return appropriate matches. Hit Enter to submit.
<br />
<input type=text id="searchtext" size=30>
</form>
</div>
<div class="searchy" id="searchresults">
</div>
什么提琴手交通节目? – asawyer 2011-12-29 21:50:18