Problem while accessing JSON in android 4.0.3

edited June 2012 in Enyo 2
Here I am accessing JSON using Ajax.
But it not access JSON data in android 4.0.3 tablet.
var request = new enyo.Ajax({ url: "./JSON/data.json" });
Kindly request to help us.

Comments

  • What else are you doing with the request variable? Are you setting a response handler on it? Are you calling go to make it perform the request?
  • edited June 2012
    var request = new enyo.Ajax({ url: "./JSON/startupOverview.json" });
    header = new Array("day1", "day2", "day3");
            					
    request.response(this, function (inSender, inData) 
    {
    	this.items = inData;
    	rssentries = this.items[header[0]];
    });
    
    request.go();
  • You need to bind the function you pass into response -- by default, it will think "this" refers to the global window object unless you do that. Try
    request.response(this, enyo.bind(this, function (inSender, inData) 
    {
    	this.items = inData;
    	rssentries = this.items[header[0]];
    }));
  • It's not working on android 4.0.3.
    It shows blank data.
  • edited June 2012
    This works for me:
    
    var request = new enyo.Ajax({ url: "./JSON/test.json" });
    header = new Array("day1", "day2", "day3");
            					
    request.response(enyo.bind(this, "processresult"));
    
    request.go();
    
    
    
    processresult: function(inRequest, inResponse) {
    	if (!inResponse) return;
    	this.items = inResponse;
    	rssentries = this.items[header[0]];
    }
    
  • There is a problem with accessing local files on Android 4. See here.

    It's not possible to load files with a query string appended. But enyo.Ajax always appends one even if there are no arguments.

    In Ajax.js, line 70:
    var url = [uri, args.join("&")].join("?");

    Should be something like:
    var url = args.length ? [uri, args.join("&")].join("?") : uri;

    And then with cacheBust: false it should be possible to load a local file via Ajax.
  • edited August 2012
    Because of (Ajax.js, lines 55..57)
    var parts = this.url.split("?");
    var uri = parts.shift() || "";
    var args = parts.join("?").split("&");
    args.length is always at least 1 (one).

    I'd suggest to check if args contains only an empty string and then remove that from args so args.length is zero in that case.

    Then change line 70 as suggested above.
  • edited August 2012
    Thanks for the suggestion. I've filed this problem as https://enyojs.atlassian.net/browse/ENYO-884 and will try to get a fix in ASAP.
Sign In or Register to comment.