我试图将表单详细信息发送到包含 php 脚本的文件夹,以使用 AJAX() 方法对其进行处理和验证,
但我收到“跨源请求被阻止”错误。我知道这是跨浏览器问题,但我无法找到解决方案。
- 编写代理服务器是一种选择。有人可以帮我解决这个问题吗?我对这一切都很陌生。
这是我的代码
<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>
我读了这篇文章http://www.html5rocks.com/en/tutorials/cors/ 但不能理解
. 另一种可能性是使用 CORS,但我不知道如何使用脚本与 JQUERY 函数 AJAX() 一起使用。