简体   繁体   中英

Call a webservice(.asmx) from another website/webapp using javascript

I am trying to call a webservice(.asmx) file using javascript. Heres a detailed explanation of what I am trying to do.

I have a two WebApplication projects one contains the WebService.asmx file, the other contains the javascript file. I am trying to call the method HelloWorld() located in WebService.asmx from the javascript file.

Note: I am trying to do this without using jQuery.

Please give a detailed explanation (Code and some documentation), I reviewed many examples and tried many different ways none of which worked for me.

Heres a list of things that I have tried:

  • Added [ScriptService] to the .asmx file.
  • Added Web reference to the project containing the .asmx.
  • Added Service reference to the project containing the .asmx.
  • Set EnablePageMethods property to true in my script manager.
  • Added the following code to my script manager.

     <Services> <asp:ServiceReference Path="http://localhost..." /> </Services> 

Since some details are missing from your questions, I would suggest you check the following:

  1. The webservice is not hosted on a separate domain that your web application
  2. In the HTTP request header, you are passing the proper Content-Type and also the expected Contect-Type
  3. Your server returns the same content type as expected by your javascript.
  4. If you are using Microsoft's client side AJAX library, ensure you are using the correct serializer/deserializer on the client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM