| Author |
AJAX: Call back handler didn't work
|
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
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?
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
K West
Ranch Hand
Joined: Sep 10, 2008
Posts: 58
|
|
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
|
Years teach us more than books.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56230
|
|
|
If you want your button to have submit semantics you need to specify type="submit"
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
You need to return false to keep the default action from firing.
Eric
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
Return false keeps the default action from happening.
Eric
|
 |
Dawn Charangat
Ranch Hand
Joined: Apr 26, 2007
Posts: 249
|
|
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
Joined: Feb 19, 2008
Posts: 2896
|
|
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
Joined: Apr 26, 2007
Posts: 249
|
|
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
Joined: Feb 19, 2008
Posts: 2896
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
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
Joined: Feb 19, 2008
Posts: 2896
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
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
Joined: Feb 19, 2008
Posts: 2896
|
|
Eric Pascarello wrote:Does that make sense yet?
Absolutely, Thanks Eric
|
 |
 |
|
|
subject: AJAX: Call back handler didn't work
|
|
|