<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script>
$.get("http://example.com/", function(data) {
alert(data);
});
</script>
Run Code Online (Sandbox Code Playgroud)
它对该URL执行OPTIONS请求,然后从不使用任何内容调用回调.
当它不是跨域时,它工作正常.
不应该只是jQuery与一个<script>节点进行调用,然后在加载时进行回调吗?我明白我无法得到结果(因为它是跨域的),但那没关系; 我只是希望电话通过.这是一个错误,还是我做错了什么?
使用WebAPI后端服务器处理新项目,我无法从实际网站发布到控制器,尽管Postman没有问题发布到控制器.我收到错误415,浏览器控制台记录:
HTTP415: UNSUPPORTED MEDIA TYPE - The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
(XHR)OPTIONS - http://localhost:5000/api/Users
Run Code Online (Sandbox Code Playgroud)
来自Kestrel的日志是
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 OPTIONS http://localhost:5000/api/Users 0
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 OPTIONS http://localhost:5000/api/Users 0
info: Microsoft.AspNetCore.Mvc.StatusCodeResult[1]
Executing HttpStatusCodeResult, setting HTTP status code 415
Microsoft.AspNetCore.Mvc.StatusCodeResult:Information: Executing HttpStatusCodeResult, setting HTTP status code 415
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action SchoolsChat.Controllers.UserContoller.Post (SchoolsChat) in 2.5323ms
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed …Run Code Online (Sandbox Code Playgroud) 我试图在REST中执行Web服务的html + javascript部分.以此代码为例:
<!DOCTYPE html>
<html lang="en"
<script type="text/javascript">
function testPut( url ){
var xhr = new XMLHttpRequest();
xhr.open( 'PUT', url, false );
xhr.setRequestHeader( 'Content-Type', 'text/plain' );
xhr.send( null );
}
</script>
<body>
<form name="test" action="">
<input type="button" value="Lanceur" onclick="testPut('http://fake.es:8080')" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是在Web服务器(使用web.py完成)中,我获得了OPTIONS而不是PUT:
111.111.111.111:52014 - - [15/May/2013 17:01:47] "HTTP/1.1 OPTIONS /" - 200 OK
Run Code Online (Sandbox Code Playgroud)
我怎么解决它?要删除OPTIONS请求并仅发送PUT?
asp.net ×1
asp.net-core ×1
c# ×1
http-get ×1
javascript ×1
jquery ×1
rest ×1
typescript ×1
web.py ×1