0

I am new to web dev. I am working on a project (web app, running on jetty port 8081) which is supposed to call the web services from another web app, running on jetty port 8081. How do I do that?

Amateur
  • 81
  • 1
  • 1
  • 6

1 Answers1

0

When you're running a server locally on your computer (like jetty), the root url is always localhost:portnumber

so if you have a web service running on port 8081, it can be accessed by connecting to the url http://localhost:8081

as for calling the services. Javascript offers AJAX (asynchronous javascript and xml) as a method to send and receive for example HTTP requests between the browser and the server. I suggest using jQuery's ajax implementation as it is nicely abstracted. In backbone.js the communication between the application and server is done with models and collections. Remember that backbone assumes you're running a RESTful web service serving up json.

UPDATE:

Because of the same-origin-policy of web browsers ajax can be normally used only to make calls to the origin of the site making the call (same protocol + domain name + port number). This can be circumvented in a controlled manner with for example JSONP, that instead of JSON returns arbitrary Javascript code. In jQuery's ajax, you can use JSONP to make requests to 'foreign' servers by setting the dataType as 'jsonp'.

Hope this helps!

jakee
  • 17,972
  • 3
  • 34
  • 40
  • If you add something to your answer about the cross-origin restriction he'll have to consider when calling another app's services, your answer will be complete! – erturne Aug 08 '12 at 10:09
  • as @erturne said, if you need to AJAX on a different server you need to follow this answer http://stackoverflow.com/a/3506306/1156688 – Claudiu Hojda Aug 08 '12 at 10:41
  • @claudia JSONP only allows you to GET from another domain. You can't use it to POST, PUT, DELETE, etc. We need to know how he wants to use the other service. Also the restriction is on the domain (combination of protocol, host, and port) not just the host. – erturne Aug 08 '12 at 12:14