Welcome Guest, Not a member yet? Register   Sign In
AJAX problem? - refreshed url show post values from AJAX call?
#1

(This post was last modified: 03-26-2015, 06:03 AM by blackbulldog.)

Hi,

I'm using a bootstrap modal form (displayed when user clicks a button)  to allow the user to enter some data then submit it via an ajax call to a CI controller. Then I want the CI controller that receives the AJAX request to (for now - still testing) simply refresh the page which allowed the user to fill in the modal form.

A strange thing is happening though ... the url for the page BEFORE the user clicks to open the modal form OR clicks to submit the AJAX update looks like this:

www.mysite.com/index.php/staff/index

after the AJAX call is submitted to the controller the url looks like this:
www.mysite.com/index.php/staff/index?addeventstaffdropdown=3&typeid=7&fromDate=2015-09-28&numdays=11&notes=notes

anyone know why the post variables from the AJAX call are appearing in the refreshed url?

Here's the JQuery code that does the AJAX submit:

PHP Code:
$('#addeventbutton').click(function () 
 {
 var 
staffid = $("#addeventstaffdropdown").val();
 var 
typeid = $("#typeid").val();
 var 
fromdate = $("#fromDate").val();
 var 
halforfull = $("#halforfull").val();
 var 
numdays = $("#numdays").val();
 var 
satandsun = $("#satandsun").val(); 
 var 
notes = $("#notes").val(); 
 if (
staffid == || typeid  == || fromdate.length )
 {
 
alert ('Please select a Staff member, select a Type and enter something in the From Date');
 } 
 var 
url=site_url+'/events/add_event_ajax/';
 var 
postData = {
 
      'staffid' staffid,
 
      'typeid' typeid,
 
      'fromdate' fromdate,
 
      'halforfull' halforfull,
 
      'numdays' numdays,
 
      'satandsun' satandsun,
 
      'notes' notes
     
}; 
 $.
ajax(
 {
 
type'POST',
 
urlurl,
 
data postData,
 
success: function(response)
 {

 } 
 }); 
 
   }); 

and heres the simple controller to redirect and refresh the 'current' page:

PHP Code:
public function add_event_ajax()
 {
 
redirect('staff/index''refresh'); 
 } 

Thanks for looking.
Reply
#2

Have you tried leaving out the second argument in redirect(), or changing it to 'location'?
Reply
#3

(03-26-2015, 11:08 AM)mwhitney Wrote: Have you tried leaving out the second argument in redirect(), or changing it to 'location'?

Yes, tried both but they get the same result.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB