ajax get the default value in select

ps: recent project change bug, front-end encounter problems, spent a lot of time to find out the problems here to be a record. Avoid the same problem. Just to share, to prevent the stepped pit. . .
Scene: The page shows a column of data; select a column, click Edit, jump to the edit page; a property value is displayed in the column editing page select box. (Select the default value)

First, the use of knowledge to the point

  1. ajax
    projects often applied to ajax to request data, background data accepted for display in the foreground.
    ajax is an asynchronous request, the local load data; and url requests, the page is not refreshed. But on request we can control through synchronous and asynchronous attribute async.
    The main difference with the synchronous asynchronous:
    synchronization can be defined by changing the external variable values,
    asynchronous loading efficiency can be improved

  2. Asynchronous and synchronous
    asynchronous: ajax does not affect load the entire page, and the browser loads equivalent to user actions or go separate, independent of each other, reflect Caton that there would be no point of view of the user feel as if nothing happened.
    Synchronization: Then and asynchronous Instead, he and loaded in the same line, and so the uncle crossed the road, and then go back to the people, that is, loaded it, and so the entire process is stopped, that is suspended animation status.

  3. select drop-down box to set defaults

$("#fwtxxmbUpdateTemp select[name='type']").attr("value",type);

Second, the project examples

  1. ajax request data in the edit page is opened, there will be a dynamic drop-down box
var typename="";
var typecode="";
function qeuryTempletnameList(){
	$.ajax({
		url: XXXX,  //请求地址
		type: "POST",
		async:false,    // 设置成同步,typename,typecode外部变量才能接受值
		dataType: "json",
		success : function(data){  
			 var datas = data.data;
			 var optionstring ="";
             for (var i =0 ; i < datas.length ; i++) {                 
                 optionstring += "<option value=\"" + datas[i].TYPECODE + "\" >" + datas[i].TYPENAME + "</option>";  
                 typename = datas[i].TYPENAME;
                 typecode = datas[i].TYPECODE;
             }
             $("#type").html("<option value=\"\">--请选择--</option>" + optionstring);            
		}
	});
}

In the Insert Picture described here ajax
2. Click on the show is the default

$.open({
					title:title,
					width:"700px",
					height:"80%",
				    content:$("#xxx").html(),
				    btns:btns,
				    success : function(){	
				        qeuryTempletnameList();		    					    	
				    	var type = data.data.type;     //data.data是另个请求的返回的数据,在这里我没有写
				    	//通过设置value属性值,获取select值
                        $("#Temp select[name='type']").attr("value",type);	   	
				    }
	})

Effect: // selected by default to the data editor page from the list page
Here Insert Picture Description

Published 16 original articles · won praise 3 · Views 540

Guess you like

Origin blog.csdn.net/outdata/article/details/98956481