I am developing a web application using JSP & Servlet.
I am new to AJAX and JQuery.
I am sending two request from my jsp page to servlet using following code:
$(document).ready(function()
{
var $ul = $(SALUTATION);
$.get('MyServletName?action=cmbSALUTATION', function(responseJson)
{
$.each(responseJson, function(index, item)
{
$('<option>').text(item).appendTo($ul);
});
});
setValSALUTATION();
});
function setValSALUTATION()
{
$.get('ProfileContactsMain?action=cmbSALUTATIONValue', function(responseJson)
{
$.each(responseJson, function(index, item)
{
$("#SALUTATION").val(item);
});
});
}
First one fills the values in html combobox and second one sets the value in combobox for that record from the database. Combobox is filled everytime, but the value for that particular record is not set everytime, sometimes setValSALUTATION() is executed before the data is loaded in the combobox.
so is anything wrong in my code? or is there any better way to do this….
Thanks in advance….
1 Answer