[英]JQuery.ajax() method not executing
我有一個按鈕,該按鈕調用如下所示的JavaScript方法:
processSelection = function(filename) {
//alert('method reached');
$.ajax({
url: "sec/selectUsers.php",
data: "filename="+filename,
cache: false,
dataType:'html',
success: function(data) {
//$('#uploader').html(data);
$('#noUsers').sortOptions();
values = $('#noUsers').children();
for (i = 0; i < values.length; i++) {
$(values[i]).bind('dblclick',switchUser);
}
$('#addButton').bind('click',addSelection);
$('#removeButton').bind('click',removeSelection);
$('#submitButton').bind('click',addUsersToFile);
},
error: function (request, textStatus, errorThrown) {
alert('script error, please reload and retry');
}
}); /* ajax */
}
它不會轉到selectUsers.php
腳本,也不會發布錯誤消息。 當我點擊“添加用戶”按鈕時,它什么也沒做。 其他方法: switchUser
, removeSelection
, addSelection
和addUserstoFile
已經定義。
我對JavaScript和php相當陌生,並已在我們的網站上分配了此項目,以進行維護。 我的php_error.log也不顯示錯誤。 如果有人對這個特定問題有任何建議,或者是一般性的調試,我將不勝感激。
這是點擊事件:
<input type="button" value="add users" onclick="processSelection('<?=$drFile['name']?>')"/>
好的,
為了簡化我的問題,我這樣做:
processSelection = function(){
//alert('method reached');
$.ajax({
url: "sec/testPage.php",
cache: false,
success: function() {
alert('success');
},
dataType:'html',
error: function (request, textStatus, errorThrown) {
alert('script error, please reload and retry'); }
});
}
其中testPage.php只是其中包含一些值的表。
現在,當我單擊按鈕時,它顯示為“成功”,但從不顯示testPage.php
dataType: 'HTML'
據我所知必須在成功方法之前。 如果仍然無法正常工作,請嘗試以下操作:
它不會顯示測試頁,因為您沒有在當前正文中添加任何內容。 如果您在屏幕上看到“成功”,則腳本成功執行。 您需要做的就是在testPage中生成html,將所有html分配給php變量,然后回顯而不是像返回它一樣
echo $myhtmlgenerated
並改變
success: function() { ....
至
success: function(result) {
$(body).append(result);
}
或者您可以使用它並指定一個特殊的div來保存該頁面的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.