How to save and use variable in jquery
Hi,following is a working code for displaying the value in 2 div's disp and bus.
$.ajax({
type: "POST",
// url: "Busbooking.aspx/ConductorTable",
url: "Busdetails.aspx/BindData1",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var s = msg.d;
var k = s.split("--");
$('#disp').html(k[0]);
filter1();
$('#bus').html(k[1]);
},
error: function (xhr) {
alert(xhr.responseText);
}
});
the data is coming from server. and working fine.
my requirement is to store msg.d in a variable and next time the data should display from stored variable.
likethis
var temp;
if (temp.length == 0) {
$.ajax({
type: "POST",
// url: "Busbooking.aspx/ConductorTable",
url: "Busdetails.aspx/BindData1",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
temp = msg.d;
var s = msg.d;
var k = s.split("--");
$('#disp').html(k[0]);
filter1();
$('#bus').html(k[1]);
},
error: function (xhr) {
alert(xhr.responseText);
}
});
}
else {
var s = temp;
var k = s.split("--");
$('#disp').html(k[0]);
filter1();
$('#bus').html(k[1]);
}
is it possible.
I tried the above code .but variable temp is showing as undefined
How to solve
Regards
Baiju