I am calling Struts2.3 dojo autocompleter onChange and updating a text field according to autocompleter value using jquery ajax. if autocompleter enter value is not in database then i want to call an action to add that item first in database.
my javascript code:-
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 code:-
<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>
i changed my some line of code in my javascript
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");
});