我知道可以获得一个空的HTTP_REFERER.在什么情况下会发生这种情况?如果我得到一个空的,它是否总是意味着用户改变了它?获得一个空的一个与获得一个空的一样?在什么情况下我也能得到它?
我想做什么
我有一个Azure免费计划托管的后端ASP.Net核心Web API(源代码:https://github.com/killerrin/Portfolio-Backend).
我还有一个客户网站,我想要消费该API.客户端应用程序不会托管在Azure上,而是托管在Github Pages或我可以访问的其他Web托管服务上.因此,域名不会排队.
考虑到这一点,我需要在Web API端启用CORS,但是我现在已经尝试了好几个小时并拒绝工作.
我如何设置客户端 它只是一个用React.js编写的简单客户端.我在Jquery中通过AJAX调用API.React网站有效,所以我知道不是这样.Jquery API调用正如我在Attempt 1中确认的那样工作.这是我如何进行调用
var apiUrl = "http://andrewgodfroyportfolioapi.azurewebsites.net/api/Authentication";
//alert(username + "|" + password + "|" + apiUrl);
$.ajax({
url: apiUrl,
type: "POST",
data: {
username: username,
password: password
},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var authenticatedUser = JSON.parse(response);
//alert("Data Loaded: " + authenticatedUser);
if (onComplete != null) {
onComplete(authenticatedUser);
}
},
error: function (xhr, status, error) {
//alert(xhr.responseText);
if (onComplete != null) {
onComplete(xhr.responseText);
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AJAX加载跨域HTML页面,但除非dataType是"jsonp",否则我无法获得响应.但是,使用jsonp,浏览器需要一个脚本mime类型,但是正在接收"text/html".
我的请求代码是:
$.ajax({
type: "GET",
url: "http://saskatchewan.univ-ubs.fr:8080/SASStoredProcess/do?_username=DARTIES3-2012&_password=P@ssw0rd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute",
dataType: "jsonp",
}).success( function( data ) {
$( 'div.ajax-field' ).html( data );
});
Run Code Online (Sandbox Code Playgroud)
有没有办法避免使用jsonp进行请求?我已经尝试过使用crossDomain参数,但它没有用.
如果没有,是否有任何方式在jsonp中接收html内容?目前,控制台在jsonp回复中说"意外<".
以下适用于IE以外的所有浏览器(我在IE 9中测试).
jQuery.support.cors = true;
...
$.ajax(
url + "messages/postMessageReadByPersonEmail",
{
crossDomain: true,
data: {
messageId : messageId,
personEmail : personEmail
},
success: function() {
alert('marked as read');
},
error: function(a,b,c) {
alert('failed');
},
type: 'post'
}
);
Run Code Online (Sandbox Code Playgroud)
我有另一个使用的函数dataType: 'jsonp',但我不需要在这个AJAX调用上返回任何数据.我的最后一招将是返回JSONP中包含的一些乱码,以使其正常工作.
任何想法为什么IE搞砸了没有返回数据的CORS请求?
我有这个jQuery代码,可以很好地交叉起源:
jQuery.ajax({
url: "http://example.appspot.com/rest/app",
type: "POST",
data: JSON.stringify({"foo":"bar"}),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (response) {
console.log("success");
},
error: function (response) {
console.log("failed");
}
});
Run Code Online (Sandbox Code Playgroud)
现在我想把它转换成Angular.js代码而没有任何成功:
$http({
url: "http://example.appspot.com/rest/app",
dataType: "json",
method: "POST",
data: JSON.stringify({"foo":"bar"}),
headers: {
"Content-Type": "application/json; charset=utf-8"
}
}).success(function(response){
$scope.response = response;
}).error(function(error){
$scope.error = error;
});
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏.
我正在创建一个在其他网站上外部加载的脚本.它加载CSS和HTML,并在我自己的服务器上正常工作.
但是,当我在另一个网站上尝试它时,它会显示这个可怕的错误:
Access-Control-Allow-Origin
Run Code Online (Sandbox Code Playgroud)
在这里你可以看到它完美加载:http://tzook.info/bot/
但在其他网站上显示错误:http: //cantloseweight.co/robot/
我将加载脚本上传到jsfiddle:http: //jsfiddle.net/TL5LK/
我尝试像这样编辑htaccess文件:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin *
</IfModule>
Run Code Online (Sandbox Code Playgroud)
或者像这样:
Header set Access-Control-Allow-Origin *
Run Code Online (Sandbox Code Playgroud)
但它仍然无效.
XMLHttpRequest可以从http:// mydomain.com/向http:// mydomain.com:81/发送请求吗?
当我尝试从包含另一个域网址的iframe将哈希值设置为父网址时,我收到以下错误:
不安全的JavaScript尝试从URL"URL2"的框架访问URL"URL1"的框架.域,协议和端口必须匹配.
我该如何解决这个问题?
我需要使用foursquare API来搜索场地.当然它是跨域的.
它在Firefox中没有任何问题,但在Internet Explorer中(7,8,9我测试过).
我的javascript代码如下:
searchVenues: function(searchQuery) {
$.ajax({
url: 'https://api.foursquare.com/v2/venues/search',
data: {
sw: bound_south_west,
ne: bound_north_east,
query: searchQuery.query,
oauth_token: FSQ_OAUTH_TOKEN,
limit: 25,
intent: 'browse',
v: 20120206
},
cache: false,
dataType: 'json',
success: function(data) {
displayResults(data, searchQuery.query);
},
error: function(xhr, status, errorThrown) {
console.log(errorThrown+'\n'+status+'\n'+xhr.statusText);
}
});
}
Run Code Online (Sandbox Code Playgroud)
在Firefox中,它可以完美地显示接收的数据.在Internet Explorer中,它在控制台上登录:
No Transport
Error
Error
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我正在开发一个内部Web应用程序.在IE10中,请求工作正常,但在Chrome中,所有AJAX请求(有很多)都是使用OPTIONS发送的,而不是我给出的任何定义的方法.从技术上讲,我的请求是"跨域".该站点在localhost:6120上提供,我正在向AJAX请求的服务是在57124. 这个关闭的jquery错误定义了问题,但不是真正的修复.
如何在ajax请求中使用正确的http方法?
编辑:
这是在每个页面的文档加载中:
jQuery.support.cors = true;
Run Code Online (Sandbox Code Playgroud)
每个AJAX都是类似的:
var url = 'http://localhost:57124/My/Rest/Call';
$.ajax({
url: url,
dataType: "json",
data: json,
async: true,
cache: false,
timeout: 30000,
headers: { "x-li-format": "json", "X-UserName": userName },
success: function (data) {
// my success stuff
},
error: function (request, status, error) {
// my error stuff
},
type: "POST"
});
Run Code Online (Sandbox Code Playgroud) cross-domain ×10
ajax ×5
jquery ×5
cors ×4
javascript ×2
.htaccess ×1
angular-http ×1
angularjs ×1
asp.net-core ×1
c# ×1
http ×1
http-headers ×1
http-referer ×1
iframe ×1
jsonp ×1
rest ×1
security ×1
webkit ×1