• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQueryForm() / jQuerySubmit issue

 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Md Uddin
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:You can not make an Ajax call to another domain

https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript

Eric


The Ajax call will be to a sub domain. I think that will work. How about in that case ?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The link I posted: https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript answers that
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic