简体   繁体   English

JQuery.ajax()方法未执行

[英]JQuery.ajax() method not executing

I have a have a button that calls a JavaScript method that looks like this: 我有一个按钮,该按钮调用如下所示的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 */
}

It is not going to the selectUsers.php script, nor is it posting the error message. 它不会转到selectUsers.php脚本,也不会发布错误消息。 When I click on my button 'add users' it does nothing. 当我点击“添加用户”按钮时,它什么也没做。 The other methods: switchUser , removeSelection , addSelection , and addUserstoFile are already defined. 其他方法: switchUserremoveSelectionaddSelectionaddUserstoFile已经定义。

I am fairly new to JavaScript and php and have been assigned this project running maintenance on our website. 我对JavaScript和php相当陌生,并已在我们的网站上分配了此项目,以进行维护。 My php_error.log shows no error either. 我的php_error.log也不显示错误。 If anyone has any advice on this specific problem, or debugging in general I would very much appreciate it. 如果有人对这个特定问题有任何建议,或者是一般性的调试,我将不胜感激。

here is the click event: 这是点击事件:

 <input type="button" value="add users" onclick="processSelection('<?=$drFile['name']?>')"/>

Okay, 好的,

To simplify my problem, I have done this: 为了简化我的问题,我这样做:

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'); }
                     });

} }

where testPage.php is just a table with some values in it. 其中testPage.php只是其中包含一些值的表。

Now when I click the button it show 'success', but never shows testPage.php 现在,当我单击按钮时,它显示为“成功”,但从不显示testPage.php

dataType: 'HTML' 

has to be before your success method as far as i know. 据我所知必须在成功方法之前。 If still does not work try the following: 如果仍然无法正常工作,请尝试以下操作:

it will not show the test page because you are not appending anything to your current body. 它不会显示测试页,因为您没有在当前正文中添加任何内容。 Your script executes successfully if you see "success"on your screen. 如果您在屏幕上看到“成功”,则脚本成功执行。 All you need to do is if you have html generated in your testPage, assign all html to a php variable and then just echo it instead of returning it like 您需要做的就是在testPage中生成html,将所有html分配给php变量,然后回显而不是像返回它一样

 echo $myhtmlgenerated 

and change 并改变

 success: function() { ....

TO

 success: function(result) { 
   $(body).append(result);
 }

or you can play around with it and specify a special div which will hold the content from that page. 或者您可以使用它并指定一个特殊的div来保存该页面的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM