| Author |
jQueryForm() / jQuerySubmit issue
|
Md Uddin
Greenhorn
Joined: Jan 11, 2006
Posts: 28
|
|
This is what I am trying to do. I have the below code which would self submit a form and would redirect it to http://someUrl.com
Now I am trying to do almost the same using JQuery
It did not submit the form. It was staying on the same page instead of going to http://someUrl.com. (I am not quite sure about the difference between ajaxSubmit() and ajaxForm())
If I use $('#myForm').submit(); instead of $('#myForm').ajaxSubmit(); it does work.
I am just wondering what I am missing here. Shouldn't the code $('#myForm').ajaxSubmit();
submit the form ?
Thank you in advance for any help.
|
MURAD (SCJP 5.0, SCWCD 1.4)
If you learn to program in Java, you'll never be without a job! (Patricia Seybold in 1998) - Knowing the syntax of Java does not make someone a software engineer. (John Knight)
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
Md Uddin wrote:It didn't work.
Sorry about your keyboard. (Please read this for an explanation.)
I am not quite sure about the difference between ajaxSubmit() and ajaxForm()
ajaxSubmit() submits the form immediately as an Ajax request. ajaxForm() instruments the form such that when it gets submitted it will route through an Ajax request rather than perform a "normal" form submission.
If I use $('#myForm').submit(); instead of $('#myForm').ajaxSubmit(); it does work.
Again "it doesn't work" isn't helpful.
If you are expecting these two statements to do that same thing, then that's the issue. .submit() will cause a normal page submission, while ajaxSubmit() will cause the form to be submitted through an Ajax request.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Md Uddin
Greenhorn
Joined: Jan 11, 2006
Posts: 28
|
|
Bear Bibeault, wow you are really fast. I couldn't even finish uploading and you already replied. Thank you.
I have updated my code, I want to give the browser back to the form action URl. What you suggest ?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
Md Uddin wrote:I want to give the browser back to the form action URl. What you suggest ?
I'm not sure what you are asking here.
|
 |
Md Uddin
Greenhorn
Joined: Jan 11, 2006
Posts: 28
|
|
Bear Bibeault wrote:
Md Uddin wrote:I want to give the browser back to the form action URl. What you suggest ?
I'm not sure what you are asking here.
Sorry, if I couldn't make my question clear.
First I would like to send an AJAX request to AnotherURL.com, depends on the response (success or failure) , I would like to submit my form and which will send it to someUrl.com
As per my understanding ajaxSubmit() should do the work. I am probably missing the very basic here (I am really new to jQuery).
Depends on the above code what I need to change if I would like to do this using ajaxForm() or ajaxSubmit() ?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
You can not make an Ajax call to another domain
https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript
Eric
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
Yeah, to make direct cross-browser request you've got to resort to a hack like jsonp (which I generally don't recommend due to security concerns).
If you need to do something like this, you'll need to look into establishing a server-side proxy.
|
 |
Md Uddin
Greenhorn
Joined: Jan 11, 2006
Posts: 28
|
|
The Ajax call will be to a sub domain. I think that will work. How about in that case ?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
|
The link I posted: https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript answers that
|
 |
 |
|
|
subject: jQueryForm() / jQuerySubmit issue
|
|
|