我有两个文件,一个是 html5,它有一个脚本,它从输入加载数据并使用 ajax 将其发送到另一个 php 文件,并在 html5 页面的 div 中显示 php 响应。我正在使用 eclipse 浏览器,但是当我在 chrome 控制台中验证我的页面时遇到了问题,我发现这一行存在问题:
xhr.send( ( s.hasContent && s.data ) || null );
这是我的 html 文件:
<!DOCTYPE html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="jquery.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
(function ($) {
// used to keep a reference to the ajax request object
var searchQuery = false;
var showUser = function (str) {
if (searchQuery != false) // if there is a pending request, cancel it
searchQuery.abort();
var searchTerm = $('#matr').val();
// if (str.trim().length < 1)
if (searchTerm.trim().length < 1 ){
$("#txtHint").html('');
return;
}
// clean up the old accordion
if ($("#accordion").length > 0)
$("#accordion").accordion('destroy');
$("#txtHint").html('searching...');
searchQuery = $.ajax({
'url':'http://IP/filename/accueil.php?q='+searchTerm,
'success':function (response) {
searchQuery = false;
$('#txtHint').html(response);
$('#accordion').accordion();
},
'error': function () {
searchQuery = false;
$('#txtHint').html('Sorry, there was an error');
}
});
};
// add the change event to the text field, once the page loads
$(document).ready(function () {
$('#matr').change(showUser);
});
})(jQuery);
</script>
</head>
<body>
<center>
<form name="data" >
<label>Enter the data :</label>
<input type="text" id="matr" >
</form></center>
<br>
<center>
<div id="txtHint"><b>Clique here to show data</b></div></center>
</div>
</body>
</html>
并且 php 文件只连接到 sql 数据库,并且:
$q =$_GET['q'];
收集值并将其显示在 div 中。
但是当我执行时,jquery.js 文件出现错误: xhr.send( ( s.hasContent && s.data ) || null );
请如果你有任何想法