I'm using the Jruby version 1.6.6. Jquery verison 1.7. And got some Data online whit a Ruby applikation: http://churbackend.impac.ch/news
Now I want to read the Json out of this data.
my request is like:
var test = $.ajax({
type: "GET",
dataType: "jsonp",
url: "http://churbackend.impac.ch/news.json",
success: function(data) {
alert('Success!');
},
error: function(xhr, error, stack) {
alert(error);
alert(stack);
}
});
I get 2 alerts back : The first (error): parseerror
And the second (stack): jQuery17036032104332288495_1329118955821 was not called
my news_controller looks like this:
def index
@news = News.all
respond_to do |format|
format.html
format.json { render :json => @news }
end
end
I tried verious diffrend things, like "text json" and almost all of the solutions whitch I found in diffrent forums. But nothing could help me solved my problem.
If you know how to deal whit this please help me, or if you need more informations just ask (I'm a beginner in forumposts)
Best wishes
Luca
Edit:
I got a solution for the parseerror:
new news_controller:
def index
@news = News.all
respond_to do |format|
format.html
format.json { render :json => @news }
format.js { render :json => @news, :callback => params[:callback] }
end
end
It works whit this ajax request:
var test = $.ajax({
type: "GET",
dataType: "jsonp",
url: "http://localhost:3000/news.js",
success: function(data) {
alert('Success!');
},
error: function(xhr, error, stack) {
alert(error);
alert(stack);
}
});
But I got a final question: How can I get this working whit a getJSON request? At the Moment it fails and just gives a empty string out.
$(document).ready(function(){
$.getJSON('http://localhost:3000/news.js', function(data) {
alert(data);
$.each(data, function(i, entries)
{
$('#maincontainer').append('<div class="AccordionTitle">'
+'<h2>'
+ entries.title
+ '</h2>'
+'</div>'
);
});
});
});