$.ajax calls don't go through on android devices

谁说我不能喝 提交于 2019-12-12 01:18:09

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/31946456/ajax-calls-dont-go-through-on-android-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!