Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send json and parse it on next html page through url in jquery?

I want to send json data through url to next html page. I checked it by emulator as I am working for mobile app, the url could not redirect to next page it is crashing at the moment what is the reason behind this. How can I parse it on next page .I am new to the jquery any idea? my json data contains result of two different sql queries in an array

 $.ajax({
         type : "POST",
         datatype : "json",
         url : "http://Localhost/phpBB3/check_pass.php?username="+ username + "&password="+ password+"&f=68",
         success: function(data){
             alert(data);

               window.location.href="source/testmenu.html?varid=" + data +"&username=" + username +"&password=" + password;
        }
 }); 

This is the code on next page

$(document).ready(function GetUrlValue(VarSearch){
       var SearchString = window.location.search.substring(1);

       var arr = SearchString.split('&');
       console.log(arr);
       //Set session variables
       var username = arr[1].split('=')[1];
       var password = arr[2].split('=')[1];
       document.getElementById('username').value = username;
       document.getElementById('password').value = password;
)};
like image 530
Hrudaya Palwe Avatar asked May 28 '15 06:05

Hrudaya Palwe


People also ask

How do you get to the next page in JSON?

Paginated JSON will usually have an object with links to the previous and next JSON pages. To get the previous page, you must send a request to the "prev" URL. To get to the next page, you must send a request to the "next" URL. This will deliver a new JSON with new results and new links for the next and previous pages.

How display JSON data in HTML using jQuery?

The jQuery code uses getJSON() method to fetch the data from the file's location using an AJAX HTTP GET request. It takes two arguments. One is the location of the JSON file and the other is the function containing the JSON data. The each() function is used to iterate through all the objects in the array.

Can I pass JSON in URL?

There are times when you may want to post JSON data to a specific URL or a web application. To achieve this, you can use the 'HTTP Request' action in your workflow. This action lets you make HTTP requests (including POST requests) through your workflows. Let's understand how this works with the help of an example.


1 Answers

in your case in first page urlencode json

window.location.href="source/testmenu.html?varid=" + encodeURIComponent(data) +"&username=" + username +"&password=" + password;

and in next page

var data= arr[0].split('=')[1];
var recieved_json = $.parseJSON(data);
like image 54
Ashish Bhagat Avatar answered Nov 13 '22 08:11

Ashish Bhagat