从本地主机到同一wifi上的另一台服务器的Ajax请求
Ajax request from localhost to another server on the same wifi
实际上,在不同的场景下,这里有几个问题。
所以我连接到了RESTful服务器所在的同一个wifi。
我在IntelliJ中打开了一个网页,它在我的机器上创建了一个本地主机服务器,这样它就可以启动我的网络摄像头。(当我试图从我的文件目录打开网页时,网络摄像头不会启动)
我正在尝试执行一个ajax请求,它看起来像这样。
$.ajax({url:'http://192.xxx.x.xx:xxxx/restful/webapi/enroll',//url:'http://localhost:63xxx/example-1.0.0.0-样本/',类型:"PUT",contentType:"application/json",processData:false,数据:数据,dataType:'json',crossDomain:true,错误:函数(xhr,状态){if(xhr.status!="201"){//201表示已创建,而不是200表示成功$("#statusEnrollmentMsg").text("失败"+状态);console.log(错误);}其他{$("#textbox").text("success");}},成功:函数(结果){$("#textbox").text("success");}})
错误代码
jquery.min.js:4 OPTIONS http://192.xxx.x.xx:xxxx/restful/webapi/enroll
send @ jquery.min.js:4
ajax @ jquery.min.js:4
OnEnroll @ example.js:130
onclick @ example.html:54
example.html:1
XMLHttpRequest cannot load http://192.xxx.x.xx:xxxx/restful/webapi/enroll. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:63xxx' is therefore not allowed access. The response had HTTP status code 404.
我总是犯这样的错误。如果不清楚,请评论,我会做出调整。
跨域已设置为true!
我想向这个服务器发送一些json对象。我不确定这是否也是合适的协议。请提供建议。
检查文档:http://api.jquery.com/jQuery.ajax/
crossDomain(默认值:对于相同域请求为false,对于跨域请求)
类型:布尔
如果您希望在domain,将crossDomain的值设置为true。这允许例如,服务器端重定向到另一个域。(添加的版本:1.5)
你的代码应该像这个
$.ajax({
url: 'http://192.xxx.x.xx:xxxx/restful/webapi/enroll',
type: 'PUT',
crossDomain: true,
contentType: "application/json",
processData: false,
data: data,
dataType: 'json',
crossDomain:true,
error: function (xhr, status) {
if(xhr.status != "201"){ // 201 means it is Created, rather than 200 which means Success
$("#statusEnrollmentMsg").text("Fail " + status);
console.log(error);
}else{
$("#textbox").text("success");
}
},
success: function (result) {
$("#textbox").text("success");
}
});
相关文章:
- 一台特定计算机的Ajax请求数据未定义/失败
- 通过开机自检将 XML 发送到另一台服务器
- 将页面正文发送到另一台服务器
- 自动打开另一台显示器上的浏览器窗口
- 从另一台服务器安全地从JS发送到PHP
- Web应用程序的体系结构/设计,对另一台服务器进行了大量Ajax调用
- 将 mp3 文件从另一台服务器下载到我的服务器
- PDF.js:从另一台服务器读取文件
- 当本地主机服务器提供实际页面时,如何使用 socket.io 与另一台服务器通信
- 安装 Node.js 在服务器上从同一网络上的另一台计算机访问节点
- 如何删除浏览器在一次请求期间添加的所有 Cookie
- 如何在一台服务器中运行不同的.js文件.js NODE JS中的文件
- 如何使用JavaScript或jQuery从另一台服务器解析XML
- JavaScript可以用于将文件推送到另一台机器或web服务吗
- 从另一台电脑访问.net web api
- 从另一台服务器获取node.js中的服务映像
- 正在将大型文件从nodejs上载到另一台服务器
- 如何使用AJAX从另一台服务器获取时间
- node-js-mongodb回调不起作用-下面的代码在我的笔记本电脑上起作用,但在另一台电脑上不起作用
- 从本地主机到同一wifi上的另一台服务器的Ajax请求