Cross-domain post to external site fails on wordpress

守給你的承諾、 提交于 2019-12-12 05:29:38

问题


I'm trying to post data to an external website from a wordpress site using Javascript, however when i send the form i'm getting this:

XMLHttpRequest cannot load https://external_site.com/embed/documents. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://my_site.com' is therefore not allowed access. The response had HTTP status code 404

I'm trying to this from a Wordpress site, this is the Javascript part that sends the data

jQuery('#send_doc').click(function(){
    var url = jQuery('#document_url').val();
    var name = jQuery('#name').val();

    var request = new XMLHttpRequest();

    request.open('POST', 'https://external_site.com/embed/documents');

    request.setRequestHeader('Content-Type', 'application/json');
    request.setRequestHeader('Authorization', 'Token my_token
    request.onreadystatechange = function () {
        if (this.readyState === 4) {
            console.log('Status:', this.status);
            console.log('Headers:', this.getAllResponseHeaders());
            console.log('Body:', this.responseText);
        }
    };

    var body = {
        'document_url': url,
        'name': name
    };

    request.send(JSON.stringify(body));
});

My question is, i understand that this is a Cross-domain problem, but my question is: Can i resolve the problem by my side or is this problem just on the externa site side?

Thank you very much for your answers

来源:https://stackoverflow.com/questions/33246760/cross-domain-post-to-external-site-fails-on-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!