【发布时间】:2012-08-03 14:03:59
【问题描述】:
这几天我一直在摸不着头脑。
我使用普通的旧 html 和 jquery 编写了一个特定于移动设备的网站。
它使用带有 json 响应的 ajax 从使用服务堆栈编写的服务中获取数据。
在桌面和我尝试过的许多不同的移动设备(android、iphone、bb 等)上都可以正常工作
但是我的手机似乎有一个特定问题(沃达丰上的三星 Galaxy S2)
当手机在 wifi 上时,ajax 可以正常工作,并且从服务接收到 json 对象并正确处理。
但是,在移动数据上,响应不会以 json 形式返回,而是以服务堆栈网页的形式返回(看起来它没有被告知正确返回 json)
我想知道标题是否会被沃达丰或其他公司剥离?
这是正在使用的 ajax 调用
$.ajax({
url: sgee.ApiUrl + "/api/GetRegionId/" + sgee.App.postcode,
type: 'GET',
dataTye: 'json',
contentType: "application/json;charset=utf-8",
cache: false,
success: function (data) {
if (data.success) {
sgee.App.EnquiryId = data.enquiryId;
sgee.App.RegionId = data.regionId;
sgee.App.RegionName = data.regionName;
$("#regionTxt").html("We have identified that you live in the " + sgee.App.RegionName + " supply region.");
sgee.EndLoading(250);
sgee.HideStep(2);
} else {
sgee.SetValidationError("#pcodeControl", "Please enter a valid UK postcode");
}
},
error: function () {
sgee.SetValidationError("#pcodeControl", "Please enter a valid UK postcode");
sgee.SendError("Error on /api/GetRegionId/", "sgee.Step1");
},
complete: function () {
}
});
这是预期的数据
{"postCode":"s63","regionId":14,"regionName":"YORKSHIRE","enquiryId":578106,"success":true,"returnedId":0}
当在移动设备上运行时,这是我收到的(不包括整个,因为它很长,但它只是 html 响应,好像我没有设置响应类型或浏览到页面)
<!doctype html>
<html lang="en-us">
<head>
<title>GetRegionId Snapshot of 03/08/2012 13:59:50</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
这真的让我发疯了,因为无法调试(至少我找不到方法)移动网络。
【问题讨论】:
-
从移动数据调用时
AcceptHTTP 标头是什么? -
捕获服务器接收到的实际请求(使用wireshark或类似工具)。发布请求。我很好奇为什么您的服务器返回一个 HTML 页面。也许请求有很大的不同。
-
你有没有想过这个问题?我有来自不同网络提供商的测试人员的报告,而不是我告诉我类似的问题。我怀疑网络提供商的代理服务器做了他们不应该做的事情(这些代理与您不能在移动网络上使用 websockets 的原因相同)。
标签: android json jquery mobile servicestack