この関数は、検索 div があるページと同じページにある限り正常に機能しますimagesearch
。ウェブサイトの別のサイトにいる場合、エラーが発生します
未定義のプロパティ '長さ' を読み取ることができません。
コンソール ポイントは行 27 を配置します。ここが if ステートメントの startif(q.length.
です。
何が問題なのか本当にわかりません。何か案は ?
function reloadSearch() {
if (!isLoading) {
var q = $('#imagesearch').val();
if (q.length >= 2) {
isLoading = true;
$.ajax({
type: 'GET',
url: 'core/flickr.php',
data: 'search=' + q,
dataType: 'html',
beforeSend: function () {
$('#imageresult').html(
'<img src="img/loading45.gif" alt="loading..." />');
if (!q[0]) {
$('#imageresult').html(
'');
return false;
}
},
success: function (response) {
$('#imageresult').html(
response);
}
});
// enforce the delay
setTimeout(function () {
isLoading = false;
if (isDirty) {
isDirty = false;
reloadSearch();
}
}, delay);
}
}
};
var delay = 1000;
var isLoading = false;
var isDirty = false;
$(document).ready(function () {
reloadSearch();
$('#imagesearch').keyup(function () {
isDirty = true;
reloadSearch();
});
});