I have stored JSON
data response from server intooldJson
variable. I want to pass this variable data to new page where another JS function is found.
Here is the first page code
$(document).ready(function(){
$("#submitform").click(function(e)
{
var MyForm = JSON.stringify($("#myform").serializeJSON());
console.log(MyForm);
$.ajax(
{
url : "http://localhost:8080/e-learner/v1/signIn",
type: "post",
headers: { 'Content-Type': 'application/json' },
data : MyForm,
success:function(data,status){
console.log(data);
if(data.status==1)
{
alert(data.errorMessage);//alert ur data here by checking data
}
else if(data.clientType == "Admin")
{
var oldJson = JSON.stringify(data);
console.log(oldJson);
$('#temp').data('oldJson', jData);
// alert("Your account created Successfully. Your Reference Key is"+data.referenceKey);
window.location.href = "Report.html"
//redirect code to dashboard page console.log(JSON.stringify(data));
}
else
{
window.location.href = "index.html"
}
},
error:function(err){
console.log(err);
alert(err.statusText);
}
});
});
});
</script>
Second page code
$.getJSON('jData', function(jsonData)
in this function I want to pass oldJson
data variable
<script>
$(document).ready(function () {
jData = $('#temp').data('oldJson');
$.getJSON('jData', function(jsonData) {
console.log(jsonData);
var s1=jsonData.data.student;
for (var i = 0; i < s1.length; i++) {
var counter = s1[i];
if(jsonData.status!="error")
{
tr = $('<tr/>');
tr.append("<td>" + counter.referencekey + "</td>");
tr.append("<td>" + counter.email + "</td>");
tr.append("<td>" + counter.clients+ "</td>");
$('table').append(tr);
}
else
{
alert(jsonData.message);
}
}
});
});
</script>