最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Successful getJSON call not returning - Stack Overflow

programmeradmin1浏览0评论

I have the following jQuery calling a method in a coldfusion component

$.getJSON("/blah/listing.cfc?method=bleep&returnformat=json",{"status":status},function(res,code)
   alert(res);
   if(res == 1){
      top.location.reload(true);
   }
   $('#chase-form .btnChase').removeAttr("disabled");
});
return true;

The call runs successfully and does what's it's supposed to. However, because of the way the component is written, it blocks the callback and the alert() does not fire. Until I sort out the reasons for the blocked callback, I need to get this page refreshing.

Is there some temporary bodge/hack I can use to just get the page to reload. I've tried a setTimeout function, but that doesn't work, e.g.

setTimeout(function(){
   $.getJSON("/blah/listing.cfc?method=bleep&returnformat=json",{"status":status},function(res,code){
      alert('here');
      $('#chase-form .btnChase').removeAttr("disabled");
      if(res == 1){
         top.location.reload(true);
      }
   }, 5000);
});

I have the following jQuery calling a method in a coldfusion component

$.getJSON("/blah/listing.cfc?method=bleep&returnformat=json",{"status":status},function(res,code)
   alert(res);
   if(res == 1){
      top.location.reload(true);
   }
   $('#chase-form .btnChase').removeAttr("disabled");
});
return true;

The call runs successfully and does what's it's supposed to. However, because of the way the component is written, it blocks the callback and the alert() does not fire. Until I sort out the reasons for the blocked callback, I need to get this page refreshing.

Is there some temporary bodge/hack I can use to just get the page to reload. I've tried a setTimeout function, but that doesn't work, e.g.

setTimeout(function(){
   $.getJSON("/blah/listing.cfc?method=bleep&returnformat=json",{"status":status},function(res,code){
      alert('here');
      $('#chase-form .btnChase').removeAttr("disabled");
      if(res == 1){
         top.location.reload(true);
      }
   }, 5000);
});
Share Improve this question edited Mar 12 at 16:08 Barmar 784k57 gold badges548 silver badges659 bronze badges asked Mar 12 at 8:39 user460114user460114 1,8954 gold badges31 silver badges56 bronze badges 7
  • How exactly does the coldfusion block the callback? It doesn't know what called it, nor does it have control over callback. Does it not return anything? What does your network tab show as a response? – mykaf Commented Mar 13 at 15:29
  • The code uses an included file within a coldfusion component, which returns a packet of html from a stored file, for sending to the Postmark API. If I hardcode it instead of using an included file, it passes through without issue. Somehow the use of an included file causes the processing to balk and not proceed. I've reached out to the ColdFusion community and nobody can explain why. It could take time to figure out and/or rebuild. The network tab displays a "1", indicating a successful return on the called function. jQuery just cannot see that return and use it. – user460114 Commented Mar 13 at 18:50
  • Did you reach out to CF community publicly? Could you link to that? Or add a minimal reproducible example to your cf code here? – mykaf Commented Mar 13 at 18:53
  • Tried editing the question to add the link, but I keep getting "Page not found". So, I'll include the link here community.adobe/t5/coldfusion-discussions/… – user460114 Commented Mar 13 at 19:11
  • 1 What debugging have you done on the CF side? Does each function return what you're expecting? What is #viewFile# in your included template? It doesn't seem to be defined anywhere in the included code. – mykaf Commented Mar 13 at 19:23
 |  Show 2 more comments

1 Answer 1

Reset to default 0

I found the problem. I started changing things around according to mykaf's suggestion and realized that I had a <cfajaximport> tag at the top of the included file. I don't know why but this caused the problem. I remove it and the original code worked fine.

发布评论

评论列表(0)

  1. 暂无评论