我正在尝试使用新的Fetch API但是遇到了Cookie问题.具体来说,在成功登录后,将来的请求中会有一个Cookie标头,但是Fetch似乎忽略了这些标头,而我使用Fetch发出的所有请求都是未经授权的.
是因为Fetch还没有准备好,或者Fetch不能与Cookies一起使用?
我用Webpack构建我的应用程序.我也在React Native中使用Fetch,它没有相同的问题.
XMLHttpRequest cannot load http://mywebservice. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
当我尝试从我的代码中运行我的Web服务时,我收到此错误.我试着找到它并尝试了许多我在网上找到的解决方案.粘贴下面的代码.
<form name="LoginForm" ng-controller="LoginCtrl" ng-submit="init(username,password,country)">
<label>Country</label><input type="text" ng-model="country"/><br/><br/>
<label>UserName</label><input type="text" ng-model="username" /></br></br>
<label>Password</label><input type="password" ng-model="password">
</br>
<button type="submit" >Login</button>
</form>
Run Code Online (Sandbox Code Playgroud)
而控制器形成相应的js是:
app.controller('LoginController', ['$http', '$scope', function ($scope, $http) {
$scope.login = function (credentials) {
$http.get('http://mywebservice').success(function ( data ) {
alert(data);
});
}
}]);
Run Code Online (Sandbox Code Playgroud)
当我从URL栏点击它时,网络服务工作正常.如何解决问题?请帮忙!
我正在使用Bottle Web Framework上的Web服务的RESTful API,并希望使用jQuery AJAX调用来访问资源.
使用REST客户端,资源接口按预期工作并正确处理GET,POST,...请求.但是当发送jQuery AJAX POST请求时,生成的OPTIONS预检请求被简单地拒绝为'405:Method not allowed'.
我尝试在Bottle服务器上启用CORS - 如下所述:http://bottlepy.org/docs/dev/recipes.html#using-the-hooks-plugin 但是从不为OPTIONS请求调用after_request挂钩.
这是我的服务器的摘录:
from bottle import Bottle, run, request, response
import simplejson as json
app = Bottle()
@app.hook('after_request')
def enable_cors():
print "after_request hook"
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
@app.post('/cors')
def lvambience():
response.headers['Content-Type'] = 'application/json'
return "[1]"
[...]
Run Code Online (Sandbox Code Playgroud)
jQuery AJAX调用:
$.ajax({
type: "POST",
url: "http://192.168.169.9:8080/cors",
data: JSON.stringify( data ),
contentType: "application/json; charset=utf-8",
dataType: …
Run Code Online (Sandbox Code Playgroud) 经过测试Postman
并且工作正常。在浏览器中我收到此错误:
从源“https://localhost:44426”访问“http://localhost:5081/api/Accounting/GetSales”处的 XMLHttpRequest 已被 CORS 策略阻止:不存在“Access-Control-Allow-Origin”标头关于所请求的资源。
使用 Angular 和 .Net6 的 Asp Net Core 项目
[DisableCors]
[HttpGet("GetSales")]
public IEnumerable<SaleDto> GetSales()
{
var result = _context.Sales.Select(x => new SaleDto
{
AccountName = x.Account.Name,
CategoryName = x.Category.CategoryName,
SaleDate = x.SaleDate,
SaleId = x.SaleId,
SaleValue = x.SaleValue,
});
return result;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用来自Foliotek的图像裁剪器Croppie,但出于某种原因它不适合我 - 而且我使用的是一个非常简单的例子.
我正在使用以下页面中的演示示例:http://foliotek.github.io/Croppie/
但我得到的只是我浏览器中的空白页面 - IE和Chrome.
我的HTML代码如下:
<html>
<head>
<link href="croppie.css" rel="Stylesheet" />
<script src="croppie.js"></script>
</head>
<body>
<div id="demo-basic"></div>
<script>
var basic = $('#demo-basic').croppie({
viewport: {
width: 150,
height: 200
}
});
basic.croppie('bind', {
url: 'cat.jpg',
points: [77, 469, 280, 739]
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我希望有人能够帮助我让这个图像裁剪工作:-)
谢谢 - 詹姆斯
ajax ×2
cors ×2
jquery ×2
angularjs ×1
asp.net-core ×1
bottle ×1
c# ×1
cookies ×1
cropper ×1
cross-domain ×1
fetch-api ×1
image ×1
javascript ×1