I would expect the following code to display 'hi mom' between the <div id='job-status'></div>
on the originating page, but it doesn't:
$(function () {
function show_status() {
$.get("<%= status_jobs_path -%>",
function(data) {
$('#job-status').html('hi mom');
}, 'json');
}
show_status();
});
The get() function being triggered: I see the request arrive at my server and a 200 OK response containing my JSON code. But an alert() inside the function(data) { ... }
body never gets called, nor is 'hi mom' displayed on the page. However, if I strip the code down to:
$(function () {
function show_status() {
$('#job-status').html('hi mom');
}
show_status();
});
... then it does display 'hi mom' within the <div id='job-status'></div>
.
IASISO (I Am Sure It's Something Obvious), but what am I missing?
My guess is that you return an invalid json
response. Try putting this in your controller action
render :json => { :message => "Hi mom" }, :status => :ok
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With