如何使用 Ajax + jQuery 调用基于 Web 服务 REST

how to call web service rest based using ajax + jquery

本文关键字:Web 服务 REST 调用 何使用 Ajax jQuery      更新时间:2023-09-26

>我正在此网址上调用Web服务。

这是我的代码.

http://jsfiddle.net/LsKbJ/8/

$(document).ready(function () {
    //event handler for submit button
    $("#btnSubmit").click(function () {
        //collect userName and password entered by users
        var userName = $("#username").val();
        var password = $("#password").val();
        //call the authenticate function
        authenticate(userName, password);
    });
});
//authenticate function to make ajax call
function authenticate(userName, password) {
    $.ajax({
        //the url where you want to sent the userName and password to
        url: "",
        type: "POST",
        // dataType: 'jsonp',
        async: false,
        crossDomain: true,
        contentType: 'application/json',
        //json object to sent to the authentication url
        data: JSON.stringify({
            Ticket: 'Some ticket',
            Data: {
                Password: "1",
                Username:"aa"
            }
        }),
        success: function (t) {
            alert(t+"df")
        },
        error:function(data){
            alert(data+"dfdfd")
        }
    })
}

响应**

**

这意味着我先调用此方法,然后调用登录方法?

该消息可能意味着在开发过程中,在编写和测试代码时,请使用 URL:

http://isuite.c-entron.de/CentronServiceAppleDemoIndia/REST/GetNewAuthentifikationTicket

而不是:

http://isuite.c-entron.de/CentronService/REST/Login

因为开发方法不需要应用程序 ID。您可以从错误消息中看到您缺少application (gu)id

The guid '61136208-742B-44E4-B00D-C32ED26775A3' is no valid application guid

你的javascript需要更新,以便根据后端sode团队使用新的url http://isuite.c-entron.de/CentronServiceAppleDemoIndia/GetNewAuthentifikationTicket

此外,即使您这样做,也无法正确获得回复,因为服务需要 web.config 中的跨域配置条目。您必须使用此引用:http://encosia.com/using-cors-to-access-asp-net-services-across-domain/并以某种方式配置服务器的 web.config,以便您可以从跨域调用它。