使用jQuery&阿贾克斯 [英] Populate second dropdown using jQuery & Ajax

查看:96
本文介绍了使用jQuery&阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据外部html文件的第一个下拉列表的值来填充第二个下拉列表,该文件仅填充选项。

I am trying to populate a second dropdown list based on the value of the first dropdown from an external html file which is only filled with the options.

外部文件:

<option value="Bedfordshire">Bedfordshire</option>
<option value="Berkshire">Berkshire</option>
<option value="Buckinghamshire">Buckinghamshire</option>

第一个下拉列表示例:

 <select>
 <option value="GB">UNITED KINGDOM</option> //option to load drop-GB.html
 <option value="US">UNITED STATES</option> //option to load drop-US.html
</select>

这些功能在FF / Safari / Chrome中都可以正常工作,但在IE或iPad中却没有p>

It all works fine in FF/Safari/Chrome but not at all in IE or iPad?

var $shipcountry = $('#ShippingCountry');
 $ShippingStateSelect = $('#ShippingStateSelect');
   $ShippingStateSelect.load('drop-GB.html'); //pre load default list

  $shipcountry.change(function () {
    var countryName = $shipcountry.val();

        $.ajax({
            type: 'GET',
            url: 'drop-' + countryName + '.html',
            success: function (msg) {       
                $ShippingStateSelect.load('drop-' + countryName + '.html');
        //fire other events on page
            },
            error: function (msg) {
               $ShippingStateSelect.hide();
        //show error message here
            },

        }); 

  });


推荐答案

您没有对传入的HTML进行排序, isnt纯元素IE失败,而Firefox / Chrome等尝试修复它。

You are not sorting you incoming HTML, and since it isnt "pure" elements IE fails while Firefox/Chrome etc tries to fix it.

您的drop-US.html包含HTML结构,如

Your drop-US.html contains HTML structure like

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- BC_OBNW -->
<head>
<title>drop-US</title>
<link href="/StyleSheets/ModuleStyleSheets.css" type="text/css" rel="StyleSheet" />
<script type="text/javascript">var jslang='EN';</script>
</head>

然后尝试插入进入选择框。

Which it then tries to insert into the selectbox.

所以你应该在ajax请求中过滤掉它,或者在源文件中删除它。 :)

So you should either filter it out in the ajax request, or remove it in the source. :)

这篇关于使用jQuery&amp;阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆