2013-02-27 3 views
0

Struts2.3 dojo autocompleter onChange를 호출하고 jquery ajax를 사용하여 자동 완성 값에 따라 텍스트 필드를 업데이트합니다. autocompleter 입력 값이 데이터베이스에 없다면 먼저 해당 항목을 데이터베이스에 추가하는 작업을 호출하고 싶습니다.자바 스크립트에서 struts2 액션을 호출하는 방법은 무엇입니까?

내 자바 스크립트 코드 : -

dojo.event.topic.subscribe("/value", function(value, key, text, widget){ 
var itemcode=value; 
var data = {itemID:itemcode,itemDes:''};   
$.post("jsondefault/callAJax.action", data, function(data, textStatus) { 
    if(data.itemDes.length===0){ 
    alert("Ihis item is not saved please save it first."); 
    window.location = "/actionName.action"; 
    }else{ 
     $('#itdes').val(data.itemDes); 
    } 
}, "json"); 
}); 

JSP 코드 : -

<div class="pull-left " style="width: 48%;"> 
<label id="item1">Item Code<br></label> 
<s:url id="itemList" action="/jsondefault/createCoupon2" method="getItems" />    
<sx:autocompleter id="itemC" href="%{itemList}" forceValidOption="true" size="24"    
name="item" autoComplete="false" showDownArrow="false" valueNotifyTopics="/value"> 
</sx:autocompleter> 
</div> <div class="pull-right " style="width: 48%;"> 
<label id="itdes1">Item Description</label> 
<input type="text" placeholder="Item Description" id="itdes"> 
</div> 
+0

확실하지 내 자바 스크립트 코드 내 일부 라인을 변경 Struts2.3 태그? –

+0

dojo 를 사용하여 를 사용하여 데이터베이스에서 자동 완성 목록을 작성합니다. –

답변

1

내가 왜 당신이 도장을 사용하는

dojo.event.topic.subscribe("/value", function(value, key, text, widget){ 
var itemcode=value; 
alert(text);  
var data = {itemID:itemcode,itemDes:''};   
$.post("jsondefault/callAJax.action", data, function(data, textStatus) { 
    if(data.itemDes.length===0){ 
     var where_to= confirm("This item is not saved, Do you want to save it?"); 
     if (where_to== true) 
     { 
     window.location="addItem.action"; 
     } 
     else 
     { 
     window.location="createCoupon1.action"; 
     } 
    }else{ 
     $('#itdes').val(data.itemDes); 
    } 
}, "json"); 
}); 
관련 문제