OK for starters this is a mobile app that i am building with PhoneGap. I am sending request over Cross-domains. using JSONP and ajax and sending response from Rails 3 with JSON.
I want to receive the data and parse it out into separate records so i can display it in a table.
i have tried
JSON.parse(data)
JSON.parse(data.results)
when i alert:
alert(data)
====> [object OBJECT]
alert(data.results)
====> [object OBJECT],[object OBJECT],[object OBJECT]
and have been unsuccessful
AJAX call:
$.ajax({
type: "GET",
dataType: "jsonp",
// test
url: "http://192.168.1.65:3000/" + ajax_url,
cache: false,
//data: ajax_data,
data: 'auth_token='+ auth_token + '&' + ajax_data,
success: function(data) {
if (data.response.status === 200 && callback.onSuccess) {
callback.onSuccess.call(this, data.response.data);
}
else if (data.response.status >= 400 && callback.onError) {
callback.onError.call(this, data.response.data.error);
}
if (callback.onComplete) {
callback.onComplete.call(this, data.response.data);
}
}
});
Rails response code:
render :json => { :response => { :status => 200, :data => {:results => results} } }, :callback => params[:callback]
I am receiving the response and when i console log the data
i get this:
When i console log data.results
i get this
Edit to Question:
i dont want to hard code data.results[0].variable
for each variable then data.results[1].variable
there could be 100's