如何通过使用jQuery的ajax调用webservice的凭据?(how to pass cred

2019-07-18 22:04发布

我使用jQuery AJAX调用是这样的:

$.ajax({
         url: WEBSERVICE_URL,
            type: "GET",
            dataType: "application/json; charset=utf-8",                   
            username: "admin",  // Most SAP web services require credentials
            password: "admin",
            processData: false,
            contentType: "application/json",
            success: function() {
               alert("success");
            },
            error: function() {
                   alert("ERROR");
                },
    });

还是呼叫不会Web服务。 每次我收到错误警报。 一些机构可以帮我在这吗?

Answer 1:

尝试使用后的方法类型,大多数Web服务被固定,并使用后需要transimssion,并没有得到

加来帮助您调试错误和响应文本到你的错误。

 $.ajax({
     url: WEBSERVICE_URL,
     type: "POST", //This is what you should chage
     dataType: "application/json; charset=utf-8",
     username: "admin", // Most SAP web services require credentials
     password: "admin",
     processData: false,
     contentType: "application/json",
     success: function () {
         alert("success");
     },
     error: function (xhr, ajaxOptions, thrownError) { //Add these parameters to display the required response
         alert(xhr.status);
         alert(xhr.responseText);
     },
 });


Answer 2:

如果你正在做跨域请求:

$.ajax({
    url: "yoururl",
    type: "GET",
    dataType: 'json',
    xhrFields: {
         withCredentials: true
    }
});


文章来源: how to pass credentials for a webservice using jquery ajax call?