O
O
orest8312013-12-16 15:05:20
JavaScript
orest831, 2013-12-16 15:05:20

How to send xml using Ajax request to another domain?

$.ajax({
            type: 'POST',
            url: "https://domain.com",
            crossDomain: true,
            data: xml,
            dataType: 'xml',
            success: function(responseData, textStatus, jqXHR)
            {
                console.log(responseData);
            },
            error: function(responseData, textStatus, errorThrown)
            {
                console.log(responseData, textStatus, errorThrown);
            }
        });


Mistake:
XMLHttpRequest cannot load https://domain.com  No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://demo.ua' is therefore not allowed access.
How to send such a request?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
maxaon, 2013-12-16
@maxaon

If the server is not yours, then there is little you can do. You can use reverse proxy to proxy your requests. For example Apache .
And if yours, use CORS . Add the "Access-Control-Allow-Origin" header and it will work.
However, if you need to send POST requests, then make sure the requests do not contain additional headers (eg "X-Requested-With: XMLHttpRequest"). Because in the presence of additional headers, with an unsafe method, a HEAD request is additionally made to obtain the "Access-Control-Allow-Headers" header.

V
Vit, 2013-12-16
@fornit1917

In an amicable way, for cross-domain requests, you need to use JSONP.
There are other options, for example read here javascript.ru/ajax/cross-domain-scripting

M
mayorovp, 2013-12-16
@mayorovp

If the server is yours, just set the correct Access-Control-Allow-Origin header. If the server is not yours - make a browser extension, they can send requests to another domain *.

O
orest831, 2013-12-17
@orest831

Unfortunately the server is not mine.

X
xmeoff, 2013-12-17
@xmeoff

@orest831 Might as well search here for similar questions before asking .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question