2

我读了很多关于这个问题的话题。我并不孤单,但我没有读到一个好的答案。我有一个带有 jquery 的 ajax 请求。我的回答是好的(200),但是 jquery 有一个错误。

url = 'http://127.0.0.1:8000/api/route?'+str
console.log(url);
jQuery.ajax({
  type: 'GET',
  url: url,
  //dataType:"json",

  success: function(data, textStatus, jqXHR) {
        console.log(data);  
  },
  error: function(jqXHR, textStatus, errorThrown) {
        console.log("error AJAX");
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
  }
});

如果我在网络浏览器中打开我的 URL,一切似乎都正常:

{"version": 0.3,"status":0,"status_message": "Found route between points","route_geometry": "i|lV_sdeAuzfh@e`mP|}fh@lrlP","route_instructions": [],"route_summary":{"total_distance":1630115,"total_time":23,"start_point":"","end_point":""},"alternative_geometries": [],"alternative_instructions":[],"alternative_summaries":[],"route_name":["",""],"alternative_names":[["",""]],"via_points":[[3.83957,11.49760 ],[3.83905,11.49980 ]],"hint_data": {"checksum":639660167, "locations": ["y3MCAAAAAADUAAAAHgAAAEi713xf8-s_1dsFAECLEQC", "r3MCAAAAAAAQAAAADwAAAOsLxO6CrOA_odsFAByMEQB"]},"transactionId": "OSRM Routing Engine JSON Descriptor (v0.3)"}

在 Firebug 中,我可以阅读:

Réponse
Content-Language    fr
Content-Type    text/html; charset=utf-8
Date    Sun, 23 Jun 2013 20:33:51 GMT
Server  WSGIServer/0.1 Python/2.7.3
Vary    Accept-Language, Cookie
Requête
Accept  */*
Accept-Encoding gzip, deflate
Accept-Language fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Host    127.0.0.1:8000
Origin  null
User-Agent  Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0

我无法摆脱这个问题。你能告诉我我的错误在哪里吗?firebug 中总是有我的“错误”:

error AJAX
Object { readyState=0, status=0, statusText="error"}
error
(an empty string)

我的服务器将返回“json”,如果我在响应中放入正确的内容类型,并且在 jquery 中,同样的错误:

GET http://127.0.0.1:8000/api/route?q=a&loc=3.839923...6665779&loc=3.839130971521939,11.499844431876904

200 OK
        27ms    
jquery.min.js (ligne 5)
ParamètresEn-têtes
Réponse
Content-Language    fr
Content-Type    application/json
Date    Sun, 23 Jun 2013 20:49:49 GMT
Server  WSGIServer/0.1 Python/2.7.3
Vary    Accept-Language, Cookie
Requête
Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Host    127.0.0.1:8000
Origin  null
User-Agent  Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0

谢谢问候艾蒂安

4

1 回答 1

0

看看添加 gzip 标头。我在移动设备上很难找到参考资料,但还有其他与 gzip 响应处理相关的类似问题

于 2015-10-01T08:51:18.990 回答