weixin_33743661 2010-11-09 21:52 采纳率: 0%
浏览 204

链式Jquery Ajax调用

I am trying to retrieve some information about any given webpage (namely the of the page and the of the domain) and then make a jquery asynchronous POST with the retrieved information. Unfortunately, the javascript execution reaches the $.post(), but never makes the actual web request. Here is my code:

$.get('../embed', {u: url}, function(html) {
    alert('got "' + html + '"');
    $.post('/media/add', { story: storyid, caption: caption, type: 5, title: title, content: html, meta: meta }, function(data) {
        var obj = jQuery.parseJSON(data); 
        var thumb = imageUrlFromMedia(obj);
        var clip = addToClipboard(obj.id, thumb || '/img/icons/embedly.png', obj.name);
    });
});

Is it even possible to make another ajax call in the success handler of $.get()? Has anyone here had any success with multiple chained HttpRequests before?

  • 写回答

1条回答 默认 最新

  • 喵-见缝插针 2010-11-09 22:13
    关注

    You can use $.ajax to find errors in the XML HTTP requests or JSON parsing (may not work for JSON parsing unfortunately). That should still display as text even if it fails to parse. Anyways, to get failure messages refactor as so

    $.ajax({
      url: '../embed',
      data: {u: url},
      success: function(html){
        ..
         $.post
        ..
      },
      error: function(XMLHTTPRequest, textStatus, errorThrown){
         //Danger Will Robinson
      }
    });
    

    If you don't see a second request, this is the request that is failing. If you still don't find an error, try doing the same with the $.post. You should consider refactoring $.post to $.ajax. By the way, parseJSON is automatic if you use $.getJSON instead of $.post. This is akin to dataType: 'json' within $.ajax.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料