$ .ajax调用不在android设备上通过 [英] $.ajax calls don't go through on android devices

查看:148
本文介绍了$ .ajax调用不在android设备上通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javascript代码:

  var googledocsurl =https://docs.google.com/viewer?url=; 
$ .ajax({
url:window.localStorage.getItem('basePath')+'pdf / GetPdfUrls',
type:GET,
data:{id :window.localStorage.getItem('userid')},
dataType:json,
beforeSend:function(){$ .mobile.loading('show');},
success:function(returnValue){
for(var i = 0; i< returnValue.length; i ++){
$('#pdfList')。append(< li>< a onclick = \window.open('+ googledocsurl + window.localStorage.getItem('basePath')+ returnValue [i] .pdfUri +\','_blank','location = yes')\ >+ returnValue [i] .PdfCreationDate +< / a>< / li>)
}
},
错误:function(){

},
complete:function(){$ .mobile.loading('hide');},
})

如果我尝试这个ajax调用模拟器和ripply它的工作没有问题,但像我一样,我试图在我的Android设备上它的工作原理是1/50,



<$>

在Visual Studio中可以看到的错误

 无法加载资源:net :: ERR_NAME_NOT_RESOLVED 
GetPdfUrls(0,0)

如果我点击GetPdfUrls(0,0)我可以看到响应,它填充了数据,但由于某种原因,这给了我和错误,但就我可以看到它是正确的



回应:

  [{pdfUri:Image / GetPdf / 8259ff54-6cd2-48dd-a0dc-d39b255e9bad,PdfCreationDate:2014-12-08},{pdfUri:Image / GetPdf / f05ff375-45e2-429b-a8fc-2c9d660df263,PdfCreationDate:2014-12-08},{pdfUri:Image / GetPdf / 211feab8-9715-4942-bf8c-f7e95188c987,PdfCreationDate: 2014-12-08},{pdfUri:Image / GetPdf / 6ded622b-2d3e-4151-8be3-01070d1b9d69,PdfCreationDate:2014-12-08},{pdfUri:图片/ GetPdf / f34adfa9-7bbf-4db9-b7ee-92fd619b0dc0,PdfCreationDate:2014-12-08},{pdfUri:Image / GetPdf / b6e5e56c-68d3-4662-a00e-b11dc09bfd9a,PdfCreationDate :2014-12-08},{pdfUri:Image / GetPdf / cc633e61-adcd-414d-bfc7-d09a30e05b01,PdfCreationDate:2014-12-15}] 

如果你需要更多的信息,请问和病尽我所能提供!
预先感谢所有的帮助

解决方案

好吧,我现在不觉得蠢...



接缝像手机没有任何互联网,当它没有连接到WiFi网络,它接缝丢失与路由器的随机连接,并连接到另一个wifi网络没有互联网连接),具有相同的信号强度,然后随机变化(猜测它采取具有最佳信号强度的已知网络)。



我很幸运logcat日志,看到这种变化发生其他明智的我会卡住一段时间:/



无论如何感谢所有的帮助!


Javascript code:

                var googledocsurl = "https://docs.google.com/viewer?url=";
                $.ajax({
                    url: window.localStorage.getItem('basePath') + 'pdf/GetPdfUrls',
                    type: "GET",
                    data: { id: window.localStorage.getItem('userid') },
                    dataType: "json",
                    beforeSend: function () { $.mobile.loading('show'); },
                    success: function (returnValue) {
                        for (var i = 0; i < returnValue.length; i++) {
                            $('#pdfList').append("<li><a onclick=\"window.open('" + googledocsurl + window.localStorage.getItem('basePath') + returnValue[i].pdfUri + "\', '_blank', 'location=yes')\">" + returnValue[i].PdfCreationDate + "</a></li>")
                        }
                    },
                    error: function () {

                    },
                    complete: function () { $.mobile.loading('hide'); },
                })

if i try this ajax call on the emulator and ripply it works no problem but as so on as i try it on my android device it works like 1/50 times, it's kind of inconsistent and this makes it really hard to fix or understand

The error that i can see in Visual Studio

Failed to load resource: net::ERR_NAME_NOT_RESOLVED
GetPdfUrls(0,0)

and if i click "GetPdfUrls(0,0)" i can see the response and it's populated with data but for some reason this gives me and error but as far as i can see it's all right to me(especially sens it works 1 out of 50 times i try)

The response:

[{"pdfUri":"Image/GetPdf/8259ff54-6cd2-48dd-a0dc-d39b255e9bad","PdfCreationDate":"2014-12-08"},{"pdfUri":"Image/GetPdf/f05ff375-45e2-429b-a8fc-2c9d660df263","PdfCreationDate":"2014-12-08"},{"pdfUri":"Image/GetPdf/211feab8-9715-4942-bf8c-f7e95188c987","PdfCreationDate":"2014-12-08"},{"pdfUri":"Image/GetPdf/6ded622b-2d3e-4151-8be3-01070d1b9d69","PdfCreationDate":"2014-12-08"},{"pdfUri":"Image/GetPdf/f34adfa9-7bbf-4db9-b7ee-92fd619b0dc0","PdfCreationDate":"2014-12-08"},{"pdfUri":"Image/GetPdf/b6e5e56c-68d3-4662-a00e-b11dc09bfd9a","PdfCreationDate":"2014-12-08"},{"pdfUri":"Image/GetPdf/cc633e61-adcd-414d-bfc7-d09a30e05b01","PdfCreationDate":"2014-12-15"}]

if you need more info just ask and ill try my best to provide! Thanks in advance for all the help

解决方案

Well don't i feel stupid now...

Seams like the phone don't have any internet when it's not connected to a wifi network and it seams to loses the connection to the router at random and connect to another wifi network (with no internet connection) that have the same signal strength and then change back at random (guess it take the known network with the best signal strength).

I was lucky i watch the logcat log and saw this change happen other wise i would have been stuck for a while :/

Anyway thanks all for your help!

这篇关于$ .ajax调用不在android设备上通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆