admin管理员组文章数量:1279085
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?
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?
Share Improve this question asked Dec 30, 2011 at 4:23 fearless_foolfearless_fool 35.2k25 gold badges145 silver badges230 bronze badges 5- Do you see the success result in firebug / chrome dev tools? – Adam Rackis Commented Dec 30, 2011 at 4:32
-
1
Are you sure the response is valid JSON? jQuery will still redirect to the
error
callback (ordeferred.fail
for$.get
) if parsing fails. – Jonathan Lonowski Commented Dec 30, 2011 at 4:33 - 1 Yeah, I don't see that acronym catching on. In regards to your question, are you sure the JSON object being returned is valid and properly structured? Also, is this a same-domain request or cross-domain? – Aaron Commented Dec 30, 2011 at 4:33
- have you tried outputting to the console what the return data contained? – Joseph Commented Dec 30, 2011 at 4:56
- see below -- the problem was that I was returning mal-formed JSON, which jQuery silently drops. So @jonathan had it right. – fearless_fool Commented Jan 2, 2012 at 5:58
1 Answer
Reset to default 12My guess is that you return an invalid json
response. Try putting this in your controller action
render :json => { :message => "Hi mom" }, :status => :ok
本文标签: javascriptWhy isn39t my jQueryget() callback being calledStack Overflow
版权声明:本文标题:javascript - Why isn't my jQuery.get() callback being called? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741259195a2367277.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论