非常に奇妙な問題: 2 つの部分からなるドロップダウンがあり、州を選択すると 2 つ目のドロップダウンが追加され、その州の MSA エリアのリストが表示されます。
これは、次のように、選択ドロップダウンでエリアのリストを返すコントローラーへの JQuery Get 要求を使用して行われます。
jQuery(function($) {
// when the #area_state field changes
$("#area_state").change(
function() {
// make a call and replace the content
var state = $('select#area_state :selected').val();
if(state == "") state="0";
jQuery.get(
'/getmsas/' + state,
function(data){ $("#msas").html(data); }
)
return false;
}
);
})
注 - このコードは、次のチュートリアルから改作されました: http://www.petermac.com/rails-3-jquery-and-multi-select-dependencies/
これは Chrome と IE では正常に機能しますが、Firefox (13.0.1) では機能せず、次の 2 つのエラーが発生します。
Error: junk after document element
Source File: http://localhost:3000/getmsas/Connecticut
Line: 2, Column: 1
Source Code:
<select id="area_msa" name="area[msa]"><option value="">Select Area (Optional)</option>
と
Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point
in the hierarchy" code: "3" nsresult: "0x80530003 (HierarchyRequestError)" location:
"http://localhost:3000/assets/jquery.js?body=1 Line: 6498"]