Here is an example of code, that attempts to featch AJAX data from /Ajax/_AjaxGetItemListHelp/
URL. Upon success, it removes all items from dropdown list with id
= OfferTransModel_ItemID
and then it fills it with new items based on AJAX call's result:
if (productgrpid != 0) {
$.ajax({
type: "POST",
url: "/Ajax/_AjaxGetItemListHelp/",
data:{text:"sam",OfferTransModel_ItemGrpid:productgrpid},
contentType: "application/json",
dataType: "json",
success: function (data) {
$("#OfferTransModel_ItemID").empty();
$.each(data, function () {
$("#OfferTransModel_ItemID").append($("<option>
</option>").val(this['ITEMID']).html(this['ITEMDESC']));
});
}
});
}
Returned AJAX result is expected to return data encoded as AJAX array, where each item contains ITEMID
and ITEMDESC
elements. For example:
{
{
"ITEMID":"13",
"ITEMDESC":"About"
},
{
"ITEMID":"21",
"ITEMDESC":"Contact"
}
}
The OfferTransModel_ItemID
listbox is populated with above data and its code should look like:
<select id="OfferTransModel_ItemID" name="OfferTransModel[ItemID]">
<option value="13">About</option>
<option value="21">Contact</option>
</select>
When user selects About
, form submits 13
as value for this field and 21
when user selects Contact
and so on.
Fell free to modify above code if your server returns URL in a different format.