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!
– Walter Gandarella
Yes. Do you know if there are any phonegap restrictions when using smartphones? Any more settings? Same request works on pc by browser.
– Jadson de O. Rosa
All my phonegap apps work perfectly this way without any restrictions.
– Walter Gandarella
Ah, I have a suspicion. In your configuration XML, in the option to enable backgrounds, set pata *. That is, all backgrounds this should work
– Walter Gandarella
would be this: <access origin="*" />
– Jadson de O. Rosa
Exactly. Authorizes for all origins.
– Walter Gandarella
didn’t work, man.
– Jadson de O. Rosa
I’ll give you a search
– Walter Gandarella
Thank you I’ll do it here too.
– Jadson de O. Rosa