This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Ajax call from HTML file not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax call from HTML file not working" Watch "Ajax call from HTML file not working" New topic
Author

Ajax call from HTML file not working

Gagan Popli
Greenhorn

Joined: Apr 17, 2011
Posts: 12
Hello,

I am facing a very weird issue, where, when i try to make a ajax call to submit a form from onload of an HTML file, I always get an error response, and the action url is never hit.

If i use the traditional way of document.form.submit(), then the action url is hit successfully.

Below is the NewFile.html i have created to test ajax submit.


Please help, why it is not submitting the form and hitting the action class. Where am i wrong.
Thanks
Regards
Gagan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60755
    
  65

Please take the time to choose an appropriate forum for your posts. This forum is for questions on general Java. For more information, please click this link ⇒ CarefullyChooseOneForum.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60755
    
  65

Your form action is wrong. You apparently did not put the real form action in your post, so there's no way to tell what's wrong with it.
Gagan Popli
Greenhorn

Joined: Apr 17, 2011
Posts: 12
Sorry for that Bear and thanks for moving it to appropriate forum.

To answer you question, basically i have used tokens in place of the actual server name and port id only for the post.

Since i am using my company's server name and port, so i could not provide those details.

Sorry for the confusion.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60755
    
  65

Then we cannot help you. The action URL is wrong and if you can't at least show us even its format, then you're pretty much on your own. Can you not even show us a representative format?
Gagan Popli
Greenhorn

Joined: Apr 17, 2011
Posts: 12
Sure Bear, its like this



Please do let me know, if you are looking for something else.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60755
    
  65

Gagan Popli wrote:action="https://server.domain.com:12345>/action/welcome"

Why is there an > after the port? Why are you putting the protocol, domain and port in the URL? Are you submitting to a different server than the web app that generated the page this form is on?
Gagan Popli
Greenhorn

Joined: Apr 17, 2011
Posts: 12
Sorry for the typo there, it is supposed to be without ">". Below is the corrected one:



And yes you were right, the page is on different server and i am trying to make an ajax call to a different server for the backend logic. But the domian remains same, only servers are different.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60755
    
  65

Open up the JavaScript debugger in your browser and see what it's telling you. It will let you know if the request fails and why.
 
 
subject: Ajax call from HTML file not working
 
Similar Threads
How to access java script file from jsp page
Creating a masked popup in JavaScript
Getting duplicate values on the onChange event of dropdown list
change event is firing twice
retrieve value at servlet from javascript.