• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AJAX: Call back handler didn't work

 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 58
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
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
If you want your button to have submit semantics you need to specify type="submit"
 
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 need to return false to keep the default action from firing.


Eric
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Return false keeps the default action from happening.

Eric
 
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:Does that make sense yet?


Absolutely, Thanks Eric
reply
    Bookmark Topic Watch Topic
  • New Topic