简体   繁体   中英

jquery function not redirecting url

I am working with codeigniter and jquery. I am using ajax to send some info to a codeigniter function to perform a db operation , in order to update the page. After the operation is complete I am trying to refresh the page. However the refresh works inconsistently and usually I have to reload the page manually. I see no errors in firebug:

           var message = $('#send_message').val()
               if ((searchIDs).length>0){
                   alert("searchIDs "+searchIDs );
               $.ajax({
                   type: "POST",
                   url: "AjaxController/update",
                   data:{ i : searchIDs, m : message },                        
                   dataType: 'json',
                   success: function(){
                       alert("OK");
                   },
                   complete: function() {
                        location.href = "pan_controller/my_detail";
                   }
               })
               .done(function() { // echo url in "/path/to/file" url
                // redirecting here if done
                alert("OK");
                location.href = "pan_controller/my_detail";
                });

                } else { alert("nothing checked") }
              break;

How can I fix this?

addendum: I tried changing to ;

  $.ajax({
                   type: "POST",
                   url: "AjaxController/update",
                   data:{ i : searchIDs, m : message },                        
                   dataType: 'json',
                   .done(function() { // echo url in "/path/to/file" url
                    // redirecting here if done
                        alert("REFRESHING..");
                        location.href = "pan_controller/my_detail";
                    });
                  }
               })

This is just defaulting to the website homepage. again, no errors in firebug

添加窗口对象的location.href是这样的:

window.location.href = "pan_controller/my_detail";

Try to use full path like

$.ajax({a
               type: "POST",
               url: "YOURBASEPATH/AjaxController/update",
               data:{ i : searchIDs, m : message },                        
               dataType: 'json',
               .done(function() { // echo url in "/path/to/file" url
                // redirecting here if done
                    alert("REFRESHING..");
                    location.href = "YOURBASEPATH/pan_controller/my_detail";
                });
              }
           })

BASEPATH should be like this " http://www.example.com "

Try disabling the csrf_enabled (config/config.php) and trying it. If that works, then re-enable the protection and, instead of compiling data yourself, serialize the form; or, at least include the csrf hidden field codeigniter automatically adds. You can also use GET to avoid the CSRF protection, but that's least advisable of of the solutions.

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