简体   繁体   中英

JQuery.ajax() method not executing

I have a have a button that calls a JavaScript method that looks like this:

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. When I click on my button 'add users' it does nothing. The other methods: switchUser , removeSelection , addSelection , and addUserstoFile are already defined.

I am fairly new to JavaScript and php and have been assigned this project running maintenance on our website. My php_error.log shows no error either. 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.

Now when I click the button it show 'success', but never shows 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

 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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