Mobile app with error

Asked

Viewed 92 times

2

I am developing an application using Apache Cordova + Jquery mobile. At a certain point I am doing the following:

var nome = $("#txtNome").val();
var sobrenome = $("#txtSobrenome").val();
var sexo = $("#selectSexo").val();
var email = $("#txtEmail").val();
var login = $("#txtLogin").val();
var senha = $("#txtSenha").val(); 
$.ajax({  
headers: {
  'Accept': 'application/json',
  'Content-Type': 'application/json' 
},
url: mainURL + usuarioURL + '/inserir',
type: 'post',
dataType: 'json',
success: function(resp){
  $.mobile.loading('hide');
  alert(resp.status);
},
error: function(e){
  alert('Error occured: ' + e);
},
beforeSend: function(){
  $.mobile.loading('show');
},

data: JSON.stringify({
  nome: nome,
  sobrenome: sobrenome,
  sexo: sexo,
  email: email,
  login: login,
  senha: senha
})
});

In the browser this works perfectly, but when I do the same on mobile, an error occurs and the following message appears: Error Ocurred: [Object Object]

Does anyone know the reason? Thank you. The logs are presented below:

    /www/gu.js: Line 55 : readyState: 0
    getResponseHeader: function ( key ) {
    var match;
    if ( state === 2 ) {
    if ( !responseHeaders ) {
    responseHeaders = {};
    while ( (match = rheaders.exec( responseHeadersString )) ) {
    responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
    }
    }
    match = responseHeaders[ key.toLowerCase() ];
    }
    return match == null ? null : match;
    }
    getAllResponseHeaders: function () {
    return state === 2 ? responseHeadersString : null;
    }
    setRequestHeader: function ( name, value ) {
    var lname = name.toLowerCase();
    if ( !state ) {
    name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
    requestHeaders[ name ] = value;
    }
    return this;
    }
    overrideMimeType: function ( type ) {
    if ( !state ) {
    s.mimeType = type;
    }
    return this;
    }
    statusCode: function ( map ) {
    var code;
    if ( map ) {
    if ( state < 2 ) {
    for ( code in map ) {
    // Lazy-add the new callback in a way that preserves old ones
    statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
    }
    } else {
    // Execute the appropriate callbacks
    jqXHR.always( map[ jqXHR.status ] );
    }
    }
    return this;
    }
    abort: function ( statusText ) {
    var finalText = statusText || strAbort;
    if ( transport ) {
    transport.abort( finalText );
    }
    done( 0, finalText );
    return this;
    }
    state: function () {
    return state;
    }
    always: function () {
    deferred.done( arguments ).fail( arguments );
    return this;
    }
    then: function ( /* fnDone, fnFail, fnProgress */ ) {
    var fns = arguments;
    return jQuery.Deferred(function( newDefer ) {
    jQuery.each( tuples, function( i, tuple ) {
    var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
    // deferred[ done | fail | progress ] for forwarding actions to newDefer
    deferred[ tuple[1] ](function() {
    var returned = fn && fn.apply( this, arguments );
    if ( returned && jQuery.isFunction( returned.promise ) ) {
    returned.promise()
    .done( newDefer.resolve )
    .fail( newDefer.reject )
    .progress( newDefer.notify );
    } else {
    newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
    }
    });
    });
    fns = null;
    }).promise();
    }
    promise: function ( obj ) {
    return obj != null ? jQuery.extend( obj, promise ) : promise;
    }
    pipe: function ( /* fnDone, fnFail, fnProgress */ ) {
    var fns = arguments;
    return jQuery.Deferred(function( newDefer ) {
    jQuery.each( tuples, function( i, tuple ) {
    var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
    // deferred[ done | fail | progress ] for forwarding actions to newDefer
    deferred[ tuple[1] ](function() {
    var returned = fn && fn.apply( this, arguments );
    if ( returned && jQuery.isFunction( returned.promise ) ) {
    returned.promise()
    .done( newDefer.resolve )
    .fail( newDefer.reject )
    .progress( newDefer.notify );
    } else {
    newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
    }
    });
    });
    fns = null;
    }).promise();
    }
    done: function () {
    if ( list ) {
    // First, we save the current length
    var start = list.length;
    (function add( args ) {
    jQuery.each( args, function( _, arg ) {
    var type = jQuery.type( arg );
    if ( type === "function" ) {
    if ( !options.unique || !self.has( arg ) ) {
    list.push( arg );
    }
    } else if ( arg && arg.length && type !== "string" ) {
    // Inspect recursively
    add( arg );
    }
    });
    })( arguments );
    // Do we need to add the callbacks to the
    // current firing batch?
    if ( firing ) {
    firingLength =
04-28 19:24:58.367  21790-21790/com.greeningu I/chromium﹕ [INFO:CONSOLE(55)] "readyState: 0
    getResponseHeader: function ( key ) {
    var match;
    if ( state === 2 ) {
    if ( !responseHeaders ) {
    responseHeaders = {};
    while ( (match = rheaders.exec( responseHeadersString )) ) {
    responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
    }
    }
    match = responseHeaders[ key.toLowerCase() ];
    }
    return match == null ? null : match;
    }
    getAllResponseHeaders: function () {
    return state === 2 ? responseHeadersString : null;
    }
    setRequestHeader: function ( name, value ) {
    var lname = name.toLowerCase();
    if ( !state ) {
    name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
    requestHeaders[ name ] = value;
    }
    return this;
    }
    overrideMimeType: function ( type ) {
    if ( !state ) {
    s.mimeType = type;
    }
    return this;
    }
    statusCode: function ( map ) {
    var code;
    if ( map ) {
    if ( state < 2 ) {
    for ( code in map ) {
    // Lazy-add the new callback in a way that preserves old ones
    statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
    }
    } else {
    // Execute the appropriate callbacks
    jqXHR.always( map[ jqXHR.status ] );
    }
    }
    return this;
    }
    abort: function ( statusText ) {
    var finalText = statusText || strAbort;
    if ( transport ) {
    transport.abort( finalText );
    }
    done( 0, finalText );
    return this;
    }
    state: function () {
    return state;
    }
    always: function () {
    deferred.done( arguments ).fail( arguments );
    return this;
    }
    then: function ( /* fnDone, fnFail, fnProgress */ ) {
    var fns = arguments;
    return jQuery.Deferred(function( newDefer ) {
    jQuery.each( tuples, function( i, tuple ) {
    var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
    // deferred[ done | fail | progress ] for forwarding actions to newDefer
    deferred[ tuple[1] ](function() {
    var returned = fn && fn.apply( this, arguments );
    if ( returned && jQuery.isFunction( returned.promise ) ) {
    returned.promise()
    .done( newDefer.resolve )
    .fail( newDefer.reject )
    .progress( newDefer.notify );
    } else {
    newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
    }
    });
    });
    fns = null;
    }).promise();
    }
    promise: function ( obj ) {
    return obj != null ? jQuery.extend( obj, promise ) : promise;
    }
    pipe: function ( /* fnDone, fnFail, fnProgress */ ) {
    var fns = arguments;
    return jQuery.Deferred(function( newDefer ) {
    jQuery.each( tuples, function( i, tuple ) {
    var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
    // deferred[ done | fail | progress ] for forwarding actions to newDefer
    deferred[ tuple[1] ](function() {
    var returned = fn && fn.apply( this, arguments );
    if ( returned && jQuery.isFunction( returned.promise ) ) {
    returned.promise()
    .done( newDefer.resolve )
    .fail( newDefer.reject )
    .progress( newDefer.notify );
    } else {
    newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
    }
    });
    });
    fns = null;
    }).promise();
    }
    done: function () {
    if ( list ) {
    // First, we save the current length
    var start = list.length;
    (function add( args ) {
    jQuery.each( args, function( _, arg ) {
    var type = jQuery.type( arg );
    if ( type === "function" ) {
    if ( !options.unique || !self.has( arg ) ) {
    list.push( arg );
    }
    } else if ( arg && arg.length && type !== "string" ) {
    // Inspect recursively
    add( arg );
    }
    });
    })( arguments );
    // Do we need to add the callbacks to the
    // current firing batch?
    if ( firing ) {
    firingLength = list.length;
    // With
  • The log printed the entire Javascript file!

  • Yes. Do you know if there are any phonegap restrictions when using smartphones? Any more settings? Same request works on pc by browser.

  • All my phonegap apps work perfectly this way without any restrictions.

  • Ah, I have a suspicion. In your configuration XML, in the option to enable backgrounds, set pata *. That is, all backgrounds this should work

  • would be this: <access origin="*" />

  • Exactly. Authorizes for all origins.

  • didn’t work, man.

  • I’ll give you a search

  • Thank you I’ll do it here too.

Show 4 more comments

1 answer

0

Here, in date, you don’t need to convert json to string.

data: { nome: nome, sobrenome: sobrenome, sexo: sexo, email: email, login: login, senha: senha }

Plus, I don’t see a mistake

  • So if I don’t convert, when the message arrives on the server, an error occurs, because it looks like this for example: first name=fffffff&last name=ffffffff&sex=M&email=fffffffff&login=fffffff&password=fffffff and Webservice is waiting for a JSON object

  • Ahhh got it. The webservice itself awaits a json as post. got it. The statement I made was to pass as normal POST. Do the following, debugging using alerts is complicated because an alert does not display the contents of an object, so it appears [Object Object]. Use the console.log(e); but to see the error you must use with the smartphone that is using test connected to the PC and with the soft ADB (in case of Andoid) running for you to check the error that appears.

  • If you cannot use ADB type software, make this modification in its error function: Function(e){ var _txt = '; $.each(e, Function(_k,_v){ _txt += _k+': '+_v+' n'; }); Alert(_txt); } this will display a more detailed alert. Tell us what error appears.

  • Then I used console.log(e) and it was presented as follows: 04-27 23:28:05.857 22593-22593/com.greeningu D/Cordovalog file://android_asset/www/gu.js: Line 55 : [Object Object] 04-27 23:28:05.857 22593-22593/com.greeningu I/Chromium [INFO:console(55)] "[Object Object]", source: file://android_asset/www/gu.js (55)

  • Displayed the contents of the _txt variable on the console. appeared a very large code, I think it does not fit in the comments.

  • Edit the question and add this text

  • Ready Walter, log added

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.