176
rated 0 times
[
183]
[
7]
/ answers: 1 / hits: 10830
/ 10 Years ago, wed, june 4, 2014, 12:00:00
I have a node server and an application from another server doing a AJAX jsonp request via jquery to get a json array of parameters, but when i request the data the jquery throws this error:
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
The request is sent and i get the response, but i can't get the data in the javascript client-side
Node server:
var my_http = require('http');
var databaseUrl = leitordecarga; // username:[email protected]/mydb
var collections = [tables]
var db = require(mongojs).connect(databaseUrl, collections);
var callback = [];
db.tables.find(function(err,values){
if(err || !values){
console.log('error');
}else{
values.forEach(function(value){
callback.push(value);
});
}
});
my_http = require(http);
my_http.createServer(function(request,response){
response.writeHeader(200, {Content-Type: application/json});
response.write(JSON.stringify(callback));
response.end();
}).listen(8080);
Javascript in client-side:
$(document).ready(function(){
$.ajax({
url:'http://localhost:8080/mongo.js',
dataType:'jsonp',
type: GET,
jsonp : callback,
contentType: application/jsonp,
success: function(data){
console.log(data);
},
error: function(data){
console.log(data.getResponseHeader());
}
}).done(function( data ) {
console.log(data);
});
});
im using jquery 2.1.0 but i've tried other versions and the error persists
My question is how i can get the data in the success clause
More From » jquery