Making AJAX() call result into Cross-Origin Request Blocked error

南笙酒味 提交于 2020-01-04 06:30:29

问题


I was trying to send a form details to a folder containing the php script to process and validated it using AJAX() method ,

But I am getting "Cross-Origin Request Blocked" error . I know this is cross browser problem but I am not able to find out a solution for this .

  1. Writing a Proxy server is one option . Can someone help me out with this I am very new to all this .

here is my code

<script>
    *<![CDATA[*/
    $(document).ready(function(){       
        $("#abusoForm #enviar").livequery("click", function(e){ 
            e.preventDefault();
            console.log("Click is working");
            var hidden = $('#mensaje').val();
            var category = $('#opcmarcar').val();
            var name = $('#nombre').val();
            var phone = $('#telefono').val();
            var mail = $('#email').val();
            var cf_mail = $('#confirma_email').val();
            var k = ""
            var z = "anotherdomain.com";
            var otro = $('#otro_email').val();
            var E = $("#abusoForm #enviar").val();

            //Ajax call happening here 
            var vajx = $.ajax({
                url: z,
                type: "POST",
                data: { 
                    'h': hidden, 
                    'c': category,
                    'n': name,
                    'p': phone ,
                    'm': mail,
                    'cm': cf_mail,
                    'otro1': otro,
                    "enviar": E,
                    async: false
                }
            }).responseText;

            //Now I have to use the variable vajx to post a message about the submition of the form ;
            $('#resultip').html(vajx);
        })
    });
    /*]]>*/
</script>

I read this article http://www.html5rocks.com/en/tutorials/cors/ but cant understand much

. Another possiblity would be to use CORS but I am not getting it how to use the script to use with JQUERY function AJAX().

来源:https://stackoverflow.com/questions/23883261/making-ajax-call-result-into-cross-origin-request-blocked-error

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