【发布时间】:2011-12-30 05:51:57
【问题描述】:
我已经为此挣扎了半天或更长时间。我无法弄清楚出了什么问题。我去掉了其他 javascript 函数、php 代码等;而且我仍然会重新加载页面,而不是没有返回任何内容的异步调用。 Firebug 也不显示 XHR 调用。
Jquery 已正确加载并且适用于其他功能。只是任何 ajax 或 jSON 调用都无法异步工作。
我什至将按键功能更改为一个简单的按钮单击处理程序,结果相同......没有。
如果我直接加载“findmatch.php”页面,它会生成正确的结果。
同一目录中的另一个程序毫不费力且完美地使用了大量 ajax 和 jSON 调用。相同的文档类型,相同版本的 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>
【问题讨论】:
-
Fiddler 流量显示什么?