在另一页上填充Ajax成功数据不起作用 [英] Fill ajax success data on another page is not working

查看:90
本文介绍了在另一页上填充Ajax成功数据不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从database调用数据,并希望将数据填充到控件上.因此,我正在使用如下的Ajax webmethod

I am calling data from database and want to fill the data on the controls. So for that, I am using Ajax webmethod like below

function getAllRecordForCurrentRow(val) {
        debugger;
        var row = val.parentNode.parentNode;            
        var ID = row.cells[7].innerText.trim();

        $.ajax({
            url: "VSATApprover.aspx/GET_DATA_FOR_CURRENT_RECORD_APPROVER",
            dataType: "json",
            type: "POST",
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({ ID: ID }),
            async: true,
            processData: false,
            cache: false,
            success: function (r) {
                //alert(r.d.SAP_ID);
                $('#txtSapId').val([r.d.SAP_ID]);
                $('#txtContactdetails').val([r.d.CONTACT_DETAILS]);
                window.open('VSATUpdateForm.aspx', '_blank');

            },
            error: function (xhr) {
                alert('Error while selecting list..!!');
            }
        })
    }

我的问题是

success函数下需要填写的值在另一页上,因此无法正常工作.那么我应该如何填充值

The value which is under success function needs to be filled is on another page and by this way it is not working. So how should I fill the values

推荐答案

您只需要将这些值设置为某些localStorage,然后在下一页上就需要从document.ready上的localStorage获取它.考虑下面的示例:

You just need to set these values to some localStorage and then on the next page you need to get it from localStorage on document.ready. Consider below example:

第1页Ajax JS

success: function (r) {
         localStorage.setItem('SapID',r.d.SAP_ID);
         localStorage.setItem('ContactDetails',r.d.CONTACT_DETAILS);
         window.open('VSATUpdateForm.aspx', '_blank');
}

现在,由于您已在localStorage中找到它,因此可以在下一页的js下面编写:

Now since you have it in localStorage you can write below js in next page:

第2页JS

$(document).ready(function(){
   //get it from localStorage
   var sapid=localStorage.getItem('SapID'); 
   var contdetails=localStorage.getItem('ContactDetails');

   //set it to textboxes
   $('#txtSapId').val(sapid);
   $('#txtContactdetails').val(contdetails);
});

就是这样.

这篇关于在另一页上填充Ajax成功数据不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆