File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Calling WebService using plain JavaScript 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 "Calling WebService using plain JavaScript" Watch "Calling WebService using plain JavaScript" New topic

Calling WebService using plain JavaScript

Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
I need to call a WebService of a different domain from my application using plain JavaScript. I don’t have a liberty to use any JavaScript/Ajax libraries - I can only use plain JavaScript.

Solution must work on IE and Firefox both.

My blood is tested +ve for Java.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41052
Since XmlHttpRequest falls under the same-domain policy, you'll have to use JSONP.

Ping & DNS - my free Android networking tools app
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Wouldn't the web service need to support JSONP? If yes - it sounds like a good approach - otherwise traditional server proxy approach would work.

I found this an interesting read.

Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

In case its not clear by what I meant by a server proxy -- you'll find some good help here --
It is sorta covered in the JavaRanch Style Guide.
subject: Calling WebService using plain JavaScript
Similar Threads
Showing Hiding <s:div> tag in Struts2
Stuck using AJAX & WebService
Getting response values in a text box
GWT Error+ XFire Webservice
Struts with Ajax