使用AJAX XMLHttpRequest调用WebService

时间:2015-02-03 03:27:15

标签: javascript asp.net ajax web-services

JavaScript部分:

var request = new XMLHttpRequest();
var url = "http://localhost:21085/WebService1.asmx?op=GetModelsByID";
request.open('GET', url );
request.onreadystatechange = function () {
    if ((request.readyState === 4) && (request.status === 200)) {
        document.writeln(request.responseText);
    }}
request.send();

WebService部分:

    namespace JavaScriptAjax
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {[WebMethod]
     public string GetModelsByID()
    {
     return ("jjjjjjjjjjjjjjjjjjjjj");}}}

但是request.responseText并没有返回任何内容。 是否可以像这样调用Web服务,或者我必须使用SOAP?

0 个答案:

没有答案