I’ve made a javascript to make a list of values for a list box. The values comes from database in SQL Server. when I make some change with the values on database, the values on my list box don’t update. It seems that the browser caches the value or something, because when I clear the cache on my browser, the values in the list box update.
here is my javascript (authapp.js):
$(document).ready(function(){
$(window).load(function(){
var loads = '<table>'+
'<tr>'+
'<td align="center" class="label">'+
'<img src="../../../Images/loading.gif" alt="Please wait..."
align="middle" style="width:30px;height:30px;">'+
'</td>'+
'</tr>'+
'<tr>'+
'<td align="center" class="label">'+
'<font color="#FFFFFF" face="Arial, Helvetica, sans-serif">Loading...</font>'+
'</td>'+
'</tr>'+
'</table>';
//load selected customer
$.ajax({
type: "GET",
url: "master/authtpl/queries/get_sel_cust.asp",
data: "cunit="+$('#cunit').val()+"&ccduser="+$('#ccduser').val(),
beforeSend: function(){
$('#load_sel').block({
message: loads,
css: { border: 'none',
top: '10%',
width: '10%',
backgroundColor: '#606060',
opacity: '0.3'
}
});
},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
$('#load_sel').unblock();
if(response==undefined){
alert('List q of Selected Customer is not available!');
} else {
$('#selSelected').empty();
var cust = (typeof response.cust) == 'string' ? eval('(' + response.cust + ')') : response.cust;
// get data from json
var count = 0,strs = '';
lent = cust.length;
do {
strs += '<option value="'+cust[count].ckode+'|'+cust[count].cgrup+'|'+cust[count].cnama+'">'+cust[count].ckode+' - '+cust[count].cnama;
count++;
} while (count < lent);
$('#selSelected').append(strs);
}
}
});
});
});
and here is my query to get that value (get_sel_cust.asp):
<!-- #INCLUDE file = "../../../include/createconnection.asp" -->
<%
dwdb = Application("DWDB")
ccdappl = Application("CCDAPPL")
ckdunitkey = trim(Request.QueryString("cunit"))
ccduser = trim(Request.QueryString("ccduser"))
sql = "select distinct ckdrelasi,ckdgruprelasi,vnamarelasi "&_
"from " & dwdb & ".dwaustasia.dbo.ms_webuser_apprtpl "&_
"where ckdunitkey='"&ckdunitkey&"' and ccduser='"&ccduser&"' and ccdappl='"&ccdappl&"' "&_
"order by ckdrelasi"
objCommand.commandText = sql
'response.write sql
set aloc = objCommand.execute
if NOT aloc.BOF then
aloc.moveFirst
json = "{ ""cust"" : [ "
body_json = ""
temp = ""
WHILE NOT aloc.EOF
temp = "{"&_
"""ckode"":"""&aloc("ckdrelasi")&""","&_
"""cgrup"":"""&aloc("ckdgruprelasi")&""","&_
"""cnama"":"""&aloc("vnamarelasi")&""""&_
"},"
body_json = body_json&temp
aloc.moveNext
WEND
body_json = mid(body_json,1,len(body_json)-1)
json2 = " ] } "
hasil = json&body_json&json2
response.write hasil
end if
set objCommand = nothing
response.end
%>
and this is the list box form (default.asp):
<SELECT name="selSelected" id="selSelected" MULTIPLE SIZE="10" class="label" style="width:250px;">
</SELECT>
I don’t know where is the problem comes from. Can you tell me did I make some mistake on my coding? thanks 🙂
Try disabling the AJAX caching in jQuery:
There are loads of places caching can happen – but it’ll be easier to start with the client and work backwards.