Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法通过使用jquery传递参数来调用webservice_Javascript_Jquery - Fatal编程技术网

Javascript 无法通过使用jquery传递参数来调用webservice

Javascript 无法通过使用jquery传递参数来调用webservice,javascript,jquery,Javascript,Jquery,我使用jquery调用webservice,无论何时调用,都只得到错误结果。 我的服务器代码: [WebService(Namespace = "http://xxx.xample.org")] [WebServiceBinding( Name ="XService", Namespace="http://xxx.xample.org/XService.asmx?")] [System.Web.Script.Services.ScriptService] public class Aa

我使用jquery调用webservice,无论何时调用,都只得到错误结果。 我的服务器代码:

 [WebService(Namespace = "http://xxx.xample.org")]
[WebServiceBinding( Name ="XService", Namespace="http://xxx.xample.org/XService.asmx?")]
    [System.Web.Script.Services.ScriptService]
public class AathiService : System.Web.Services.WebService
{

    [WebMethod]
    public string IsValidUser(string UserName , string Password)
    {
       // process
       return result;

    }
}
}
然后我使用jquery调用服务,如下所示

 $("#okButton").click(function () {

       // CALLING WEBSERVICE

       var param = { UserName: 'xxxx', Password: 'xxxxx' };

       $.ajax({ type: "POST", contentType: "application/json;charset=utf-8", data: JSON.stringify(param),

           url: "http://xxx.xample.org/xService.asmx/IsValidUser", dataType: "json", async: true,

           success: function () { alert("success"); }, error: function (xhr,msg) { alert(msg + "  " + xhr.responseText); }
       });

   });

我总是得到错误的部分。我不知道我做了什么。

在您的webmethod中,您希望返回类型为“string”,但您使用数据类型JSON调用ajax调用 这将解决您的问题:

    [WebMethod]
    public JsonResult IsValidUser(string UserName , string Password)
    {
       // process
       return Json(result);

    }

只需更改async:false。问题已解决

您是否正在尝试进行跨域调用?能否在函数上获得断点?7个月后。。。这是某种异步性