如何使用ajax在dropdownliast中选择一个项目 [英] How to Selected an Item in dropdownliast using ajax

查看:65
本文介绍了如何使用ajax在dropdownliast中选择一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的专家,



我在asp.net中使用Ajax Json。以下是我使用的以下Ajax Json代码......





Dear Experts,

I am Using Ajax Json in asp.net. Here is the below code of Ajax Json that i am used......


$.ajax(
      {
        type: "POST",
        url: "../../WebService.asmx/populate_Country",
        dataType: "json",
        data: {},
        contentType: "application/json; charset=utf-8",
        success: function (json) {

         var xmlDoc = "";
         var xml = "";
         xmlDoc = $.parseXML(json.d);
         xml = $(xmlDoc);
               
         document.getElementById("ddl_Country").innerHTML = "";

         $(xml).find("Table1").each(function () {
         var County_ID = $(this).find("Country_ID").text();
         var County_Name = $(this).find("Country").text();
         var County_Selected = $(this).find("Default_Selection").text();

         $("#ddl_Country").append("<option value='" + County_ID + "' selected='" + County_Selected + "'>" + County_Name + "</option>");

                        });
                    }
                });





以下是HTML代码,







And here is the below HTML Code,


<select id="ddl_Country" name="validation-select" class="select expandable-list validate[required]">

</select>







这些是数据来自数据库..






And these are the datas from database..

Country_ID    Country         Default_Selection
  
1             Canada              NULL    
2             United States       NULL   
3             Belgium             NULL  
4             Australia           NULL    
5             New Zealand         NULL 
6             India               Selected 







我想在下拉列表中填充这些数据....



这些代码工作正常,但国家印度没有被选中......



当我在源代码中对这些数据进行硬编码时,将选择印度...



请帮助我..



谢谢和问候,



Dileep ..




And i want to populate these datas in dropdownlist....

These codes are working fine, but Country India is not selected......

When i hard coded these datas in the source, then the India will be selected...

Please Help me..

Thanks and Regards,

Dileep..

推荐答案

.ajax(
{
type: POST
url: ../../ WebService.asmx / populate_Country
dataType: < span class =code-string> json,
data:{},
contentType: 应用/ JSON; charset = utf-8
成功: function (json){

var xmlDoc = ;
var xml = ;
xmlDoc =
.ajax( { type: "POST", url: "../../WebService.asmx/populate_Country", dataType: "json", data: {}, contentType: "application/json; charset=utf-8", success: function (json) { var xmlDoc = ""; var xml = ""; xmlDoc =


.parseXML(json.d);
xml =
.parseXML(json.d); xml =


(xmlDoc);

document .getElementById( ddl_Country)。innerHTML = ;
(xmlDoc); document.getElementById("ddl_Country").innerHTML = "";


这篇关于如何使用ajax在dropdownliast中选择一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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