You must Sign In to post a response.
  • Category: JQuery

    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
  • #768163
    Hi,

    When storing the data in the Jquery level I have used the following method.

    Now the below code contains the data which we are going to take into variable.

    $(this).data('ImageName', $('img').attr('id'));


    The below code will store the data which we are got current position above.

    var StoredVar = $('Anything').data('ImageName');

    Thanks,
    Mani


  • Sign In to post your comments