3 回答

TA貢獻1820條經(jīng)驗 獲得超10個贊
var date = $(this).val();
$.ajax({
type: 'GET',
url: "http://localhost/data/check_date.php?date=" +date ,
dataType: 'text',
success: function(data) { //add data in the function which is returned from the file
alert(data);
}
});
還可以嘗試在執(zhí)行 ajax 請求之前通過在瀏覽器中單擊來打開網(wǎng)絡選項卡F12,如果您的 php 文件中存在錯誤,您可以在網(wǎng)絡選項卡中查看它,看看是否有幫助

TA貢獻1827條經(jīng)驗 獲得超4個贊
兩個錯誤:
1:
date = $(this).val();
到
var date = $(this).val();
2:
url: "http://localhost/data/check_date.php?date=" +date ",
到
url: "http://localhost/data/check_date.php?date=" +date ,
3:
success: function() {
到
success: function(data) {
所有腳本:
<script>
$(document).ready(function() {
$('#txtdate').change(function(){
var date = $(this).val();
$.ajax({
type: 'GET',
url: "http://localhost/data/check_date.php?date=" +date ,
success: function(data) {
alert(data);
}
});
});
});
</script>

TA貢獻1784條經(jīng)驗 獲得超2個贊
刪除"在url末尾提到的,因為date是要通過url傳遞的變量。
要克服所有錯誤,請將整個代碼更改為
<script>
$(document).ready(function() {
$('#txtdate').change(function(){
var date = $(this).val();
$.ajax({
type: 'GET',
url: "http://localhost/data/check_date.php?date=" +date,
success: function(date) {
alert(date);
}
});
});
});
</script>
- 3 回答
- 0 關注
- 168 瀏覽
添加回答
舉報