Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

READ ERROR on fetch with data #56

Open
dottodot opened this issue Dec 6, 2014 · 3 comments
Open

READ ERROR on fetch with data #56

dottodot opened this issue Dec 6, 2014 · 3 comments

Comments

@dottodot
Copy link

dottodot commented Dec 6, 2014

Whenever I do a fetch with data I get an error of

[ERROR] :  [REST API] READ ERROR:
[ERROR] :  {
[ERROR] :      code = 0;
[ERROR] :      data = "Unable to parse JSON string";
[ERROR] :      error = "cannot parse response";
[ERROR] :      responseJSON = "<null>";
[ERROR] :      responseText = "cannot parse response";
[ERROR] :      status = error;
[ERROR] :      success = 0;
[ERROR] :  }
[ERROR] :  [REST API] apiCall ERROR: cannot parse response
[ERROR] :  [REST API] apiCall ERROR CODE: 0
[ERROR] :  [REST API] apiCall ERROR MSG: cannot parse response

here's how I'm fetching

events.fetch({
        data : {
            user : {
                email : Titanium.App.Properties.getString("email"),
                token : Titanium.App.Properties.getString("token")
            }
        },
        processData: true,
        success : function(_model, _response) {
            $.loading.hide();
        },
        error : function(_model, _response) {
            Ti.API.info('Events Fetch Error');
            Ti.API.info(_response);
        }
    });

I've also tried JSON.stringify on the data but that causes the same error.

@leitom
Copy link
Contributor

leitom commented Dec 10, 2014

I found the problem to be the in the apiCall function on ios8 emulator.
The problem is when passing anything into xhr.send() function when not needed creates this error.

The following solution worked:

if (_options.type != 'GET' && ! _.empty(_options.data)) {
    xhr.send(_options.data);
} else {
    xhr.send();
}

@leitom
Copy link
Contributor

leitom commented Dec 10, 2014

I someone can verify this I will create a pull request.

@viezel
Copy link
Owner

viezel commented Dec 10, 2014

that looks correct.. please PR that.

leitom added a commit to leitom/napp.alloy.adapter.restapi that referenced this issue Dec 10, 2014
viezel pushed a commit that referenced this issue Dec 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants