在Rails中.load vs .get

时间:2014-01-06 17:50:56

标签: jquery ruby-on-rails ajax

我正在阅读jQuery in Action一书中的jQuery中的AJAX。有一些代码在选择下拉列表中将html加载到带有onchange事件的div中。使用$.get看起来像这样:

$(function() {

  $('#bootChooserControl').change(function(event){
    $.get(
      '/fetch_product_details',
      $(this).serialize()
    );
  });
});

我的控制器响应JavaScript:

fetch_product_details.js.erb

$('#productDetailPane').html('<%= j render "product_details" %>');

现在,下一个示例切换到$.load,如下所示:

$('#bootChooserControl').change(function(event){
  $('#productDetailPane').load(
    '/fetch_product_details',
    $(this).serialize()
});

但由于某种原因,#productDetailPane现在填充了以下文字:

$('#productDetailPane').html('
\n Item name:<\/label> Chippewa 17-inch Engineer Boot\n<\/div>\n
\n SKU:<\/label> 7141832\n<\/div>\n
\n Height:<\/label> 17 inches\n<\/div>\n
\n Colors:<\/label> Black Oi
...

好奇为什么$.load函数不能解释JavaScript?

0 个答案:

没有答案
相关问题