【发布时间】:2013-04-01 19:45:41
【问题描述】:
我创建了一个小的python 应用程序来显示demo。
HTML
<html>
<body>
<button id="button"> Click for JSON Response </button>
<div id="update"></div>
<script src="{{url_for('static', filename='jquery-1.8.3.js')}}"></script>
<script type="text/javascript">
$("#button").on('click', function(e){
$.ajax({
type: "POST",
url: "http://localhost:8888/json",
success: function(msg){
$("#update").html(msg['msg']);
}
});
});
</script>
单击该按钮会从server 生成msg。但在移动设备上,会引发以下错误。
POST http://localhost:8888/json jquery-1.8.3.js:8434
send jquery-1.8.3.js:8434
jQuery.extend.ajax jquery-1.8.3.js:7986
(anonymous function) 192.168.0.101:8
jQuery.event.dispatch jquery-1.8.3.js:3058
elemData.handle.eventHandle
$.ajax 在 android 4.2.2 的 chrome android 移动浏览器中提交失败。
编辑
1.adb forward tcp:9222 localabstract:chrome_devtools_remote
然后通过带有端口号(8888)的机器的IP地址访问,并通过在笔记本电脑中访问http://localhost:9222捕获控制台日志。
2.在$.ajax中添加console.log(err)后,console中的错误信息为
Object {readyState: 0, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}
abort: function ( statusText ) {
always: function () {
complete: function () {
done: function () {
error: function () {
fail: function () {
getAllResponseHeaders: function () {
getResponseHeader: function ( key ) {
overrideMimeType: function ( type ) {
pipe: function ( /* fnDone, fnFail, fnProgress */ ) {
progress: function () {
promise: function ( obj ) {
readyState: 0
responseText: ""
setRequestHeader: function ( name, value ) {
state: function () {
status: 0
statusCode: function ( map ) {
statusText: "error"
success: function () {
then: function ( /* fnDone, fnFail, fnProgress */ ) {
__proto__: Object
【问题讨论】:
-
您的移动设备是否在 8888 端口运行 Web 服务器?
-
@mori57:更新了更多信息。
-
加上console.log(msg);会得到什么在您的 $("#update") 行之前?看看有没有回款?如果没有,您是否尝试在调用中添加错误:以查看从服务器返回的内容?巧妙的把戏,顺便说一句,所有这些。 (对不起,我在想 jqXHR 对象的失败事件回调。)
-
post没有提交,这就是问题所在。 -
好吧,如果你从 err 对象(statusText: "error")中得到了一些东西,那么请求正在被发送。我不确定,但您可能还需要使用某些东西来确定对您的服务器的请求以接受跨域请求。 stackoverflow.com/questions/11641442/…
标签: android jquery python google-chrome