Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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
Jquery ajax调用web服务:返回未定义_Jquery_Asp.net_Web Services - Fatal编程技术网

Jquery ajax调用web服务:返回未定义

Jquery ajax调用web服务:返回未定义,jquery,asp.net,web-services,Jquery,Asp.net,Web Services,我有一个jquery ajax调用asp.net web服务,但它不工作。我有一个错误: isValid被低估。 我设置了一个断点,发现代码从未到达web服务。 Jquery: 谢谢。在Ajax完成之前,您将返回isValid。 最好的方法是编写一个函数,在Ajax调用完成时调用该函数 $.ajax({ type: "POST", url: "UserNameWebService.asmx/ValidateUserName", data: "{'strUs

我有一个jquery ajax调用asp.net web服务,但它不工作。我有一个错误:

isValid被低估。

我设置了一个断点,发现代码从未到达web服务。 Jquery:


谢谢。

在Ajax完成之前,您将返回
isValid
。 最好的方法是编写一个函数,在Ajax调用完成时调用该函数

    $.ajax({ type: "POST",
        url: "UserNameWebService.asmx/ValidateUserName",
        data: "{'strUsername': '" + $("#<%=TextUserName.ClientID%>").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function (data) {
            RenderResult(data);
        }
    });

在Ajax完成之前,您将返回
isValid
。 最好的方法是编写一个函数,在Ajax调用完成时调用该函数

    $.ajax({ type: "POST",
        url: "UserNameWebService.asmx/ValidateUserName",
        data: "{'strUsername': '" + $("#<%=TextUserName.ClientID%>").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function (data) {
            RenderResult(data);
        }
    });

你用过Firebug或类似的东西来观察请求/响应吗?你用过Firebug或类似的东西来观察请求/响应吗?我不会这么做,因为你不会从中返回任何东西。你想在这个函数中更新你的UI/结果。我们能像这样处理你代码中的返回吗?函数RenderResult(data){if(data.value==false)返回false;else返回true;}您将不会返回任何内容。通过此函数更新您的UI。那么,您对
ValidateUserName
的结果做了什么呢。e、 函数RenderResult(data){if(data==true){alert(“用户名无效”);};但我确实想退货。我最初的问题是验证文本框,这不是Ajax的工作方式。您需要等待Ajax调用的结果。此时,您对函数
ValidateUserName
的调用已经退出,因此您需要在Ajax调用的
success
方法中处理结果。我不会这样做,因为您不会从中返回任何内容。你想在这个函数中更新你的UI/结果。我们能像这样处理你代码中的返回吗?函数RenderResult(data){if(data.value==false)返回false;else返回true;}您将不会返回任何内容。通过此函数更新您的UI。那么,您对
ValidateUserName
的结果做了什么呢。e、 函数RenderResult(data){if(data==true){alert(“用户名无效”);};但我确实想退货。我最初的问题是验证文本框,这不是Ajax的工作方式。您需要等待Ajax调用的结果。此时,对函数
ValidateUserName
的调用已经退出,因此需要在Ajax调用的
success
方法中处理结果。
    $.ajax({ type: "POST",
        url: "UserNameWebService.asmx/ValidateUserName",
        data: "{'strUsername': '" + $("#<%=TextUserName.ClientID%>").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function (data) {
            RenderResult(data);
        }
    });
function RenderResult(data){
    // handle the returned result here
    var isValid = data;
}