0

ajaxを使用してRESTサービスにアクセスしようとしています。
このリンクを任意のWebブラウザーに貼り付けると、次のような結果になります。

{"SessionID":"a7f58a4a-f922-47c1-8351-d2035df4968c","SourceIP":"127.0.0.1","UserID":313}  

(セキュリティのためにリンクが変更されました)
https://thisisjustasample/Rest/Authenticate/Login?username = user&password = pass123&ip = 127.0.0.1

しかし、ajaxを使用してリンクにアクセスする運は見つかりませんでした:

「表示」部分からの呼び出し:

getdata('https://thisisjustasample/Rest/Authenticate/Login?username=user&password=pass123&ip=127.0.0.1');    

jsファイル内の関数:

function getdata(url) {
    $.ajax({
        url: url,
        type: 'GET',
        contentType: 'application/json',
        success: function (data) {
            if (data) {
                showtooltip(data);
            }
        },
        error: function (xhr, ajaxOptions, error) {
            showtooltip(xhr.status + ': ' + error);
        }
    });
}  

常に「0」ステータスを返します。また、データベースを確認しても、データに変更はありません。コードの何が問題になっていますか?

4

1 に答える 1

0

問題は、contentTypeを指定するべきではないのにjsonのコンテンツタイプを指定していることであり、パラメーターはデータの一部である必要があると感じています。

$.ajax({
    url: "https://thisisjustasample/Rest/Authenticate/Login",
    type: 'GET',
    data: "username=user&password=pass123&ip=127.0.0.1",
    success: function (data) {
        if (data) {
            showtooltip(data);
        }
    },
    error: function (xhr, ajaxOptions, error) {
        showtooltip(xhr.status + ': ' + error);
    }
});
于 2012-04-04T09:26:18.823 に答える