aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes jQueryForm() / jQuerySubmit issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jQueryForm() / jQuerySubmit issue" Watch "jQueryForm() / jQuerySubmit issue" New topic
Author

jQueryForm() / jQuerySubmit issue

Md Uddin
Ranch Hand

Joined: Jan 11, 2006
Posts: 30
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: 61612
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Md Uddin
Ranch Hand

Joined: Jan 11, 2006
Posts: 30
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: 61612
    
  67

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

Joined: Jan 11, 2006
Posts: 30
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: 15376
    
    6
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: 61612
    
  67

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

Joined: Jan 11, 2006
Posts: 30
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
The link I posted: https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript answers that
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jQueryForm() / jQuerySubmit issue