CodeIgniter Forums
Form submit with Ajax problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Form submit with Ajax problem (/showthread.php?tid=46318)



Form submit with Ajax problem - El Forum - 10-27-2011

[eluser]Cgull[/eluser]
Hello,

I have a view with a form in it and some links.

Every link is calling another form with ajax.

When the second form is submitted, I want it to close, and display a success message.

The first form should stay on the screen with the details that the user filled in.

I tried a few ways but each way caused me a problem.

Right now, what I am doing is when the second form is submitted:

Code:
function addOrderDets()
{
$.ajax({
   type: "POST",
   url: "/orders/index.php/processOrder/addOrderDets",
   success: function(data){
    
    $('#orderDetsResult').show();
  }
});
}

And in the processOrder controller:

Code:
function addOrderDets()
  {
  $this->load->model('mOrderDets');
  $products = $this->mOrderDets->addOrderDets();
  redirect('home');
  }

Of course, redirect does not work, since it refreshes the page and all the data the user capture is gone.

But how do I keep the data?

I also tried this way:

Code:
function addOrderDets()
{
$.ajax({
   type: "POST",
   url: "/orders/index.php/processOrder/addOrderDets",
   success: function(data){
   if(data)  
     $('#orderDetsResult').show();
  }
});
}

and the controller:

Code:
function addOrderDets()
  {
  $this->load->model('mOrderDets');
  $products = $this->mOrderDets->addOrderDets();
  echo "1";
  }

Then it just goes to page:
Code:
http://localhost/orders/processOrder/addOrderDets

and displays: 1.

Any help will be very appriciated. Smile