2010-11-28 85 views
0

我在从这个ajax调用返回HTML时出现问题。它在FF中工作正常,但在IE中为我提供了一个“null”alert(result.html());Ajax调用问题

这里是代码。有任何想法吗?谢谢!!!

IE中的errors变量也为null。

此外,它不会影响我在.find()中使用的元素,因为它仍然为空。

function update_price() { 
    $.ajax({ 
     url: $("form[name='MainForm']").attr('action'), 
     data: $("form[name='MainForm']").serialize() + '&btnupdateprice.x=0&btnupdateprice.y=0', 
     type: 'POST', 
     cache: false, 
     success: function (response) { 
      var errors = $(response).find("#listOfErrorsSpan"); 
      var result = $(response).find(".colors_productprice:eq(0)"); 
      alert(result.html()); 
      $(".colors_productprice:eq(0)").replaceWith('<font class="colors_productprice">' + result.html() + '</font>'); 
      $('#listOfErrorsSpan').replaceWith('<span id="listOfErrorsSpan">' + errors.html() + '</span>'); 
     } 
    }); 
} 

$(function() { 
    $("select[name^='SELECT___'],input[name^='SELECT___'][type='radio']").each(function() { 
     $(this).change(function() { 
      update_price(); 
     }); 
    }); 
    $("a[href^='javascript:change_option']").each(function() { 
     $(this).click(function() { 
      var result_href = $(this).attr('href').match(/\'(.*?)\'/)[1]; 
      var result_val = $(this).attr('href').match(/\,(.*?)\)/)[1]; 
      change_option(result_href, result_val); 
      update_price(); 
      return false; 
     }); 
    }); 
}); 

这是来自Ajax调用的HTML。

<table border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td> 
<b><font class="pricecolor colors_productprice"><span class="price_name"><font class="text colors_text"><b>Our Price: </b></font></span> 
<span class="price1">$505.00</span> 
</font> 
</b> 
</tr> 
</table> 

在FF我得到这个警报。

<span class="price_name"> Price with added options: </span><span class="price1">$505.00</span> 
+0

你希望有人通过猜测你的HTML是什么来调试你的工作。你为什么不把这个例子发布在jsFiddle或者有用的东西上?你为什么不描述你使用的是什么版本的IE? – vol7ron 2010-11-28 03:13:47

+0

IE8,我已经用Ajax调用的HTML片段更新了问题 – user357034 2010-11-28 03:24:32

回答

0

你可能有错误,这个代码

var errors=$(response).find("#listOfErrorsSpan"); 

VAR的结果= $(响应).find( “colors_productprice:EQ(0)”); alert(result.html());

我不知道,也许为$(响应)的选择是不确定的

+0

我不这么认为,因为没有生成javascript错误并且在FF中正常工作。只是不明白为什么?也许这是得到答复的错误方法。删除该行在IE中具有相同的效果。 – user357034 2010-11-28 02:53:11

0

的:EQ(0)您的查找声明可能是问题。查找(“。colors_productprice”)可能就足够了。

0

你不必</td>

不知道这是问题的根源,但FF和IE在怪异模式的工作方式不同,插入元素上飞DOM时尤其如此。