-3

With a local file JSON I get data by $.getJSON and output with jQuery mobile

$('body').off('tap').on('tap', 'ul li', function(event) {
    var jqxhr = $.getJSON("one.json", function(data) {
        console.log("success");
        alert(data.name + " " + data.one);
        $("#json").html(data.name + " " + data.one);
    }).done(function() {
        console.log("second success");
        $("#d1").html("second success");
    }).fail(function(jqxhr, textStatus, error) {
        var err = textStatus + ', ' + error;
        console.log("Request Failed: " + err);
        $("#d2").html("Request Failed: " + err);
    }).always(function() {
        console.log("complete");
        $("#d3").html("complete");
    });
});

This works well on a computer and HTC but on Samsung devices it's not working. On samsung not error,output empty div

ZKolya
  • 135
  • 7
  • If you check the parameters passed to the `fail()` handler you will get far more information. At the moment, given the lack of detail in your question, all we can do is tell you how to debug the problem, not how to actually solve it. – Rory McCrossan Mar 18 '16 at 13:18
  • On samsung not `error`,output empty `div` – ZKolya Mar 18 '16 at 13:49
  • given your code, it would seem to be impossible to have an empty div result unless the ajax request isn't even started. – Kevin B Mar 18 '16 at 14:22
  • this problem only samsumg.Android 4.2.1 – ZKolya Mar 18 '16 at 14:26
  • 1
    Does the ajax request get sent at all? If you can't answer that you haven't debugged enough. – Kevin B Mar 18 '16 at 14:40

2 Answers2

1

Reading the comments above, I believe its possible that your code might actually work with luck on one device, and fail on many many more.

The "on tap" that you use looks invalid (and its usage does come with a warning and thus, has limits). http://api.jquerymobile.com/tap/

Warning: Use tap with caution

Tap makes use of vclick and therefore should be used with caution on touch devices. See the vclick API documentation for more details.

Based on my understanding, after the tap, should come the function - not reference to any particular tags. Notice the difference between the first line in your code above, and my code below.

$('body').off('tap').on('tap', function(event) {

    var jqxhr = $.getJSON("one.json", function(data) {
        console.log("success");
        alert(data.name + " " + data.one);
        $("#json").html(data.name + " " + data.one);
    }).done(function() {
        console.log("second success");
        $("#d1").html("second success");
    }).fail(function(jqxhr, textStatus, error) {
        var err = textStatus + ', ' + error;
        console.log("Request Failed: " + err);
        $("#d2").html("Request Failed: " + err);
    }).always(function() {
        console.log("complete");
        $("#d3").html("complete");
    });
});
  • i see a problem similar to mine http://stackoverflow.com/questions/14191338/ajax-working-on-some-android-devices-not-in-other ,but probem in API – ZKolya Mar 18 '16 at 14:53
  • Define handler? Do you mean selector? You have bound the event to the body. If you want to bind it to *ul li*, then something like *$("ul > li").on("tap", function.....);* You need to read how to use tap before you use it or else you are going to depend on code without knowing limits until you or one of your users trip. –  Mar 18 '16 at 14:58
  • I did button `$('#test').on('tap', function(event) {});`. Again htc and pc work,samsung not work. – ZKolya Mar 18 '16 at 20:11
  • It sounds like you are hitting a device or android version related issue then. Did you read the jquery mobile page like I previously suggested, and the warning about using tap on touch devices? –  Mar 19 '16 at 11:12
0
if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN){
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
ZKolya
  • 135
  • 7