我在你发布的代码注意到了两个错误。我评论了旧代码,因此您可以轻松注意到更改。
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<SCRIPT>
function kin() {
//var kobj = document.getElementById("k"); // input Object
//var q = kobj.value;
var q = $("#k").val();
$.ajax({
type: "POST",
url: "zips.php",
//data:q,
data: "q="+q,
success: function(res) {
$("#result").append(res);
console.log(res);
}
});
}
</SCRIPT>
<INPUT type="text" autocomplete="off" value="" id="k"><input type="submit" value="search" onClick="kin()" data-role="button">
<DIV id="result"></DIV>
的JQuery可以让你重写你发布这样的代码:你到底做
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<SCRIPT>
$(document).ready(function() {
$("#submit").click(function(e) {
e.preventDefault();
var q = $("#k").val();
$.ajax({
type: "POST",
url: "zips.php",
data: "q="+ q,
success: function(res) {
$("#result").append(res);
console.log(res);
},
});
});
});
</SCRIPT>
<INPUT type="text" autocomplete="off" value="" id="k"><input type="submit" id="submit" value="search" data-role="button">
<DIV id="result"></DIV>
?你怎么确定它不起作用? – ohaal
优秀的问题:**我认为它不工作** – gdoron
阅读此问题,因为我认为它涉及到Ajax和Postscript ...哦,这听起来很有趣! –