如何发送跨域ajax请求 [英] How to send a cross domain ajax request
问题描述
我想发送一个跨域 ajax 请求,但我遇到了以下错误>
我尝试发送跨域请求的代码.
$(document).ready(function () {$.ajax({类型:'POST',url: "http://testdomain.com/config.php",跨域:真,数据:'rejected_by_loid='+ 1,成功:功能(味精){$('#survey').html(msg);}});});
控制台日志错误:
跨源请求被阻止:同源策略不允许读取 http://beta.paravey.com/paraveyads/config.php.(原因:缺少 CORS 标头Access-Control-Allow-Origin").
请帮我解决这个问题.
放在 config.php 之上
header('Access-Control-Allow-Origin: *');
I want to send a cross domain ajax request but I am getting below error for this I have also tried the below code which I have got from the one stack article is it possible to send a cross domain request or not.
Code which I have tried for sending cross domain request.
$(document).ready(function () {
$.ajax({
type: 'POST',
url: "http://testdomain.com/config.php",
crossDomain: true,
data: 'rejected_by_loid=' + 1,
success: function (msg) {
$('#survey').html(msg);
}
});
});
Error on console log:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://beta.paravey.com/paraveyads/config.php. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Please help me to solve this problem.
put it on top of config.php
header('Access-Control-Allow-Origin: *');
这篇关于如何发送跨域ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!