1

几天来,我一直在为此挠头。

我使用普通的旧 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">

这真的让我发疯,因为无法调试(至少我找不到方法)我正在使用 android chrome 远程开发人员工具来逐步执行代码,但我无法捕获移动网络上的 http 请求和响应.

4

3 回答 3

0

只是猜测...但是您期望 json 内容对吗?如果是这样,为什么您的响应是“text/html”而不是“application/json”?

于 2012-08-03T14:19:09.490 回答
0

你有一个错字......“dataTye:'json',”。会是这样吗?

于 2012-12-12T06:58:28.230 回答
0

我认为是由于表单提交的类型。使用 post 而不是 get...

于 2015-12-14T12:14:28.330 回答