Welcome Guest, Not a member yet? Register   Sign In
Submit form using AJAX
#1

[eluser]GrootBaas[/eluser]
How can I do the same with my ajax call ...
Code:
var contract_no = $('.trSelected td:nth-child(2) div').text();
                
                $.ajax({
                               url: "<?=base_url()?>logs/update_logs",
                            global: false,
                              type: "POST",
                             async: true,
                          dataType: "html",
                              data: "con_num="+ contract_no                      
                });

as what I do with this button ...
Code:
x
<?=form_submit(array('id' => 'button', 'name' =>'btn_order', 'value' => 'test')); ?>
[code]
There must be a difference, i just dont know ...
#2

[eluser]GrootBaas[/eluser]
Solved it ...

Form needs to be explicitly submitted.

This can be done via JavaScript ....

Code:
document.get_password.submit();
#3

[eluser]narkaT[/eluser]
when you "submit()" the form you're not using ajax anymore.
the request will be aborted as soon as the form-submission is started.
#4

[eluser]GrootBaas[/eluser]
[quote author="narkaT" date="1224593206"]when you "submit()" the form you're not using ajax anymore.
the request will be aborted as soon as the form-submission is started.[/quote]

Yip, I get that.

My real time request to the server side is aborted, but the Ajax still call my CI controller, which is where the new form is being called from.

Is there a better way of doing this?
#5

[eluser]Randy Casburn[/eluser]
1) change the dataType to a JSON encoded string
2) put the fieldId+fieldcontents together as a JSON object as data
3) submit your AJAX request as you were before.

Do not 'submit' your form.
#6

[eluser]GrootBaas[/eluser]
[quote author="Randy Casburn" date="1224644716"]1) change the dataType to a JSON encoded string
2) put the fieldId+fieldcontents together as a JSON object as data
3) submit your AJAX request as you were before.

Do not 'submit' your form.[/quote]

Hi Randy,

Thank you for your reply. But I need some more help here ....

When I use Ajax, it does not submit the form. So I can not build another form.
As with form.submit, it works, but I am having trouble sending parameters across to the controller. The parameters are set up using jQuery, so I can not allocate it to a form_hidden variable used by form submit.

How can I get form parameters
Code:
var contract_no = $('.trSelected td:nth-child(2) div').text();
across to my controller, and submit the form at the same time, so that I can build another form?
#7

[eluser]Randy Casburn[/eluser]
You are mis-using AJAX. It is an extremely rare circumstance that one would have to submit a form AND send a AJAX request simultaneously. If you expect to get something back from your Asynchronous AJAX request after you submit your form, they will come back at some unexpected time and likely destroy your user's browser display.

So you can't do that. Let's get to the basics...how much content is on the page with the form? Basic header, footer, menu, form. Other than that what else?

Randy
#8

[eluser]GrootBaas[/eluser]
[quote author="Randy Casburn" date="1224659942"]You are mis-using AJAX. It is an extremely rare circumstance that one would have to submit a form AND send a AJAX request simultaneously. If you expect to get something back from your Asynchronous AJAX request after you submit your form, they will come back at some unexpected time and likely destroy your user's browser display.

So you can't do that. Let's get to the basics...how much content is on the page with the form? Basic header, footer, menu, form. Other than that what else?

Randy[/quote]

Thanks so much for taking the time to halp me ...

The form has an FlexiGrid on it. When the update button is pressed on the FlexiGrid, it calls an JavaScript function

Code:
function Flex_Select(com,grid) {
  
         if (com=='Update') {
            
                 alert('VALUE ')
                var contract_no = $('.trSelected td:nth-child(2) div').text();
                                
                $.ajax({
                               url: "<?=base_url()?>logs/update_logs",
                            global: false,
                              type: "POST",
                             async: true,
                          dataType: "JSON",
                              data: "con_num="+ contract_no                      
                });
                
              
              
         }                
    }

All I want to do, is use the value of the row selected in FlexiGrid
Code:
var contract_no = $('.trSelected td:nth-child(2) div').text();
, and build another page.
#9

[eluser]Randy Casburn[/eluser]
[quote author="GrootBaas" date="1224660596"]
The form has an FlexiGrid on it. [/quote]


Aaahhhhh....ok then...start here http://ellislab.com/forums/viewthread/75326/

That thread would be a great place to start. Your answer is closer there.

Randy
#10

[eluser]GrootBaas[/eluser]
[quote author="Randy Casburn" date="1224661433"][quote author="GrootBaas" date="1224660596"]
The form has an FlexiGrid on it. [/quote]


Aaahhhhh....ok then...start here http://ellislab.com/forums/viewthread/75326/

That thread would be a great place to start. Your answer is closer there.

Randy[/quote]

Nah mate, been there.

My FlexiGrid works, everything is completed, and working.

I just need to get my variable across to the controller and load a new form




Theme © iAndrew 2016 - Forum software by © MyBB