Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.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 Ajax调用WCF服务失败,请求响应错误_Javascript_Jquery_Ajax_Wcf_Iis - Fatal编程技术网

Javascript 使用jquery Ajax调用WCF服务失败,请求响应错误

Javascript 使用jquery Ajax调用WCF服务失败,请求响应错误,javascript,jquery,ajax,wcf,iis,Javascript,Jquery,Ajax,Wcf,Iis,使用jqueryajax调用wcfweb服务失败,请求不正确,不知道确切的问题。 它甚至不要求任何方法成功或失败。 web服务和网站都使用iis部署在同一台服务器上 错误: Failed to load resource: the server responded with a status of 400 (Bad Request) 该代码用于调用服务方法: function test(){ try { code = getValuesWritten

使用jqueryajax调用wcfweb服务失败,请求不正确,不知道确切的问题。 它甚至不要求任何方法成功或失败。 web服务和网站都使用iis部署在同一台服务器上

错误:

Failed to load resource: the server responded with a status of 400 (Bad Request)
该代码用于调用服务方法:

function test(){
     try {

       
        code = getValuesWrittenInTheURL[0] + "";

       
        var query = "select taskstatus,tasksubstatus,Lat,Lng,elementID from tasks_gvt where code = '" + code + "'";
        
        $.ajax({
            type: "POST",
            async: true,
            url: IP + "/GetData", 
            data: JSON.stringify({ Query: query }),
            dataType: "json",
            success: function (data) {
                debugger;
                console.log("data: ",data);
           
            },
            failure: function (errMsg) {
                debugger;
                console.log("err",errMsg);
                
            }
           
        });
    } catch (error) {
        console.log("alaaError", error.message);
    }
    
}
wcf web服务运营合同:

 [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "GetData", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        Response GetData(String Query);

准备好向您提供更多详细信息。

以下是我成功访问该服务的Ajax,您可以参考它:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Ajax</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>
    <script>
$(document).ready(function(){
    $("button").click(function () {
        code = "code";
        var query = "select taskstatus,tasksubstatus,Lat,Lng,elementID from tasks_gvt where code = '" + code + "'";
        da={"Query":query}
        $.ajax({
            type: "Post",
            dataType: "json",
           contentType: "application/json;charset=utf-8",
           data: JSON.stringify(da),
            url: "http://localhost/Service1.svc/GetData", success: function (result) {
        }});
    });
});
    </script>
</head>
<body>


    <button>Call WCF Rest Service</button>

</body>
</html>
{"Query":query}