0

JavaScriptで次のajax呼び出しを行っています

$.ajax({
    type: "Post",
    url: '../WebService/LoginService.asmx/LoginCheck',
    data: jsondata,
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    success: function (resp) {
        if (resp.d == true) {
            window.location.replace("../Admin/DashBoard.aspx");
            return;
        }
        jQuery("#lblex").css("display", "block");
    },
    error: function (response) {
        alert(response.responseText);
    }
});

これは、テスト時にローカルで正常に動作しますが、実稼働サーバーでこれをホストすると、サービスが見つからないと表示されます。しかし、私はパスまで閲覧することができます

../WebService/LoginService.asmx

URLを次のように変更すると

 ../WebService/LoginService.asmx?op = LoginCheck

そこでも機能します。

両方を同じように動作させるために、ローカルまたは実稼働サーバーでどのような構成変更を行う必要があるか教えてください。

4

1 に答える 1

1

If this script is inside a WebForm I would recommend you using the ResolveUrl method to ensure that proper url is generated no matter where your application is hosted:

url: '<%= ResolveUrl("~/WebService/LoginService.asmx/LoginCheck")',

If the script is not inside a WebForm but in a separate javascript file where you cannot use server side functions you could define a global javascript variable in your WebForm:

<script type="text/javascript">
    var serviceUrl = '<%= ResolveUrl("~/WebService/LoginService.asmx/LoginCheck")';
</script>

that you could later use in your separate js file:

url: serviceUrl,
于 2013-01-25T08:48:32.047 に答える