-2

アプリケーションで mvc 4 の asp.net Web API を使用しています。

コンピューターからそのWeb APIを呼び出すと、データを取得しています

$.getJSON("api/MyAction/?dt=" + dateString,
                function (data) {});

しかし、プロジェクトをサーバーにデプロイしたときは機能しません。

4

1 に答える 1

0

私はそれに対する解決策を得ました。

URLの前にサーバーパスを追加しました

すなわち

$.getJSON(GetSiteRoot() + "api/MyAction/?dt=" + dateString,
                function (data) {});

&私の方法は

function GetSiteRoot() {
    var rootPath = window.location.protocol + "//" + window.location.host + "/";

    var path = window.location.pathname;

    if (path.indexOf("/") == 0) {

        path = path.substring(1);
    }
    path = path.split("/", 1);

    if (path != "") {
        rootPath = rootPath + path + "/";

    }

    return rootPath;
}
于 2013-05-25T08:34:34.947 に答える