Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

jQueryForm() / jQuerySubmit issue

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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() ?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The link I posted: https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript answers that
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic