Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AJAX: Call back handler didn't work

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm using AJAX to store my product info into database.
This code works fine and displayed the proper message:
JSP:

JS:

But when I changed the JSP code from "Image Button" to "Button" type, the behavior changes and call back handler(processStateChange) dosent get called,

JSP:


JS:
And this weird behavior is only on FF, Chrome, But not on IE, On IE both code works and prints result.

Any pointers?

 
K West
Ranch Hand
Posts: 58
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can this be the reason?

Important: If you use the button element in an HTML form, different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will submit the content of the value attribute. Use the input element to create buttons in an HTML form.

Got it from
http://www.w3schools.com/tags/tag_button.asp

Best Luck
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want your button to have submit semantics you need to specify type="submit"
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to return false to keep the default action from firing.


Eric
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K West & Bear, thanks for the help, but I'm not submitting a FORM, but calling a JS function on 'onclick()' event.

Eric , your solution works, but with little modification, as

and you said "return false to keep the default action from firing. ", can you elaborate this ?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Return false keeps the default action from happening.

Eric
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how are you creating the "req" object ??? XMLHttp ??? ActiveXObject ???

The way you create one for MSIE is totally different for other browsers.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the default action is "processStateChange()", a call back handler, Am I right ?

Dawn Charangat wrote:how are you creating the "req" object ??? XMLHttp ??? ActiveXObject ???
The way you create one for MSIE is totally different for other browsers.

I think that wouldn't be an issue, still FYI:

 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't be sure that this is the problem... but I find some loopholes in the way you create your request object.
Try the below code:


 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that's throws an error like,
Error initializing XMLHttpRequest 1.
Error: A script from "http://localhost" was denied UniversalBrowserRead privileges.

Do you really thinks that code makes a difference ??
I just scared, looking at those "msobj" array and setting privileges for "netscape".
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dawn,

Why in the world would people need to use this:



Also MS does not recommend that you use half of the XMLHTTP values you supply in that array.

Eric
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still my question is unanswered ? I'm just making it sure.
Eric Pascarello wrote:Return false keeps the default action from happening
Sagar Rohankar wrote:And the default action is "processStateChange()", a call back handler, Am I right ?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the posts above I said: "return false keeps the default action form happening." Another way to say it it cancels the click. Does that make sense yet?

Eric
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Does that make sense yet?

Absolutely, Thanks Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic