Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

如何将option里面的value值,通过ajax提交到后台

mui.ajax({
                type:'get',
                dataType:'json',
                url:classifyUrl,
                success:function(data){
                    var len = data.length;
                    for(var i=0; i<len; i++){
                    var option = doc.createElement("option");                    
                    option.innerHTML = '<option value="">'+data[i].label+'</option>';                    
                    option.value = data[i].value;
                    currentIssueType = list.options[list.selectedIndex].value;
                    list.appendChild(option);
                    list.onchange = function(){
                    mui.alert(list.options[list.selectedIndex].value);
                    }
                    }
                }
            })        
        
            

            
//            部门分类
            mui.ajax({
                type:'get',
                dataType:'json',
                url:officeUrl,
                success:function(data){
                    var len = data.length;
                    for(var i=1; i<len; i++){
                    var option = doc.createElement("option");                    
                    option.innerHTML = '<option value="">'+data[i].name+'</option>';
                    option.value = data[i].name;
                    currentIssueType2 = list2.options[list2.selectedIndex].value;
                    list2.appendChild(option);
                    list2.onchange = function(){
                    mui.alert(list2.options[list2.selectedIndex].value);
                    }
                    }
                }
            })
            
            
            deliverButton.addEventListener('tap',function(event){
                var id = getQueryString("id");
                var deliverUrl = baseServerUrl+"/m/biz/issue/transmit?id="+id+"&issueType="+currentIssueType+"&officeId="+currentIssueType2;
                mui.ajax({
                    type:'get',
                    dataType:'json',
                    url:deliverUrl,
                    success:function(data){
                        alert(currentIssueType);
                        alert(currentIssueType2);
                    }
                })
            })
            
            

能看到alert出你的选择,但是在deliverButton里面提交的时候, alert(currentIssueType); alert(currentIssueType2);输出的却是第一个option里面的东西,怎么才能正常提交呢,球大神指教


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

currentIssueType在deliverButton调用之前没有明确的赋值。下面是我找到的一个赋值的位置,你把这个改成同步的试试。你这个应该在上面两个ajax都执行完的时候,再去执行第三个ajax才可以有值

clipboard.png

clipboard.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...