2013-04-26 146 views
0

我把Ajax调用Ajax调用内内访问元素,但在第二,该元件不被认可,例如:不能成功阿贾克斯

$.ajax({ 
    url: 'controleFatAcoes.php', 
    type: 'post', 
    dataType: 'html', 
    data: { 
     acao: 'validaenviofat', 
     id_cliente: cli.id_cliente, 
     dt_fat: cli.id_fat 
    }, 
    success: function(data) { 
     $.ajax({ 
      url: 'controleFatAcoes.php', 
      data: {id_cliente: cli.id_cliente, 
        id_fat: cli.id_fat, acao: 'getdadosnf'}, 
      type: 'post', 
      dataType: 'json', 
      success: function(dados) { 
        **$('#templateEmpresa').html(dados.empresa);** 
      } 
     )}; 
}); 

当我运行一个console.log($('#templateEmpresa')),我得到:

[context: document, selector: "#templateEmpresa", constructor: function, init: function, selector: ""…] 
+0

你可以在这里粘贴ajax()结果标题吗?这样我们可以正确地看到ajax数据的结构。 – KevinIsNowOnline 2013-04-26 12:15:26

回答

0

出来试试这个代码: 可能是因为您正在执行的第一个Ajax调用成功函数内部的第二Ajax调用的范围问题。

var firstajaxsuccess = 0; 
$.ajax({ 
    url: 'controleFatAcoes.php', 
    type: 'post', 
    dataType: 'html', 
    data: { 
     acao: 'validaenviofat', 
     id_cliente: cli.id_cliente, 
     dt_fat: cli.id_fat 
    }, 
    success: function(data) { 
     firstajaxsuccess = 1; 
    } 
}); 
if(firstajaxsuccess){ 
     $.ajax({ 
      url: 'controleFatAcoes.php', 
      data: {id_cliente: cli.id_cliente, 
        id_fat: cli.id_fat, acao: 'getdadosnf'}, 
      type: 'post', 
      dataType: 'json', 
      success: function(dados) { 
        **$('#templateEmpresa').html(dados.empresa);** 
      } 
     )}; 
} 
+0

ajax请求默认为异步... – 2013-04-26 12:24:30

+0

div #fatTemplate位于文本区域内,因为我使用插件tinyMce ... – Diego 2013-04-29 11:44:41

+0

您也可以考虑将$('#templateEmpresa')对象保存到变量中在您的AJAX功能中访问它。 – Mysteryos 2013-04-30 05:26:10