我已經與這一半的一天或更多的摔跤。我無法弄清楚什麼是錯的。我剝去了其他的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