Consumption of webservice with authentication from ajax form [closed]

0

A problem arose when trying to consume a web service xml from JS with ajax since it has authentication prior to the delivery of information and I can not inspect the form of the credentials requested.

try the following:

function webservice() {
    $.ajax({
        url: "urlwebserv",
        type: "Post",
        data: { username: "username", password: "password" },
        dataType: 'xml',
        success: function (data) {
            $(data).find("Data").each(function () {
                $(this).find("id").text();
            });
        },
        error: function () {
            alert("Do!");
        }

    });
}

tbn try this:

function webservice() {
    $.ajax({
        url: "urlwebserv",
        type: "Post",
        username: "username", 
        password: "password",
        dataType: 'xml',
        success: function (data) {
            $(data).find("Data").each(function () {
                $(this).find("id").text();
            });
        },
        error: function () {
            alert("Do!");
        }

    });
}

The question is: can ajax enter a web service that requests authentication by form? and then access the information delivered from an xml

browser errors:

  

Failed to load resource: the server responded to a status of 401   (Unauthorized).

     

Failed to load urlwebsrv: Response to preflight request does not pass   access control check: No 'Access-Control-Allow-Origin' header is   present on the requested resource. Origin ' link ' is   therefore not allowed access. The response had HTTP status code 401.

please help.

    
asked by Max Fuentes 28.09.2017 в 21:43
source

1 answer

0

For security reasons, browsers restrict cross-origin HTTP requests initiated within a script.

For example, XMLHttpRequest follows the same-origin policy. Therefore, an application using XMLHttpRequest can only make HTTP requests to its own domain.

However, for testing purposes, install this extension Allow-Control-Allow- Origin in Chrome . You activate it, and you can allow connections between domains.

    
answered by 28.09.2017 / 23:20
source