If this is your real server side code then...its completely insecure. You should never pass variables posted by users directly into your queries.

$query2 = "insert into booking(cust_email, cust_mobile, cust_name) values('$mail','$mobile','$name')";  

At least escape the values using "mysql_real_escape_string", or use prepared statements. And...dont use mysql anymore, use mysqli, which is almost identical to what you are using, but not deprecated soon.

Also, you are json encoding a string that doesnt need to be json encoded, its just a piece of text and not valid json code. This may be why @SimarjeetSingh Panghlia answer doesnt work for you.

instead of json_encoding that value, encode a structured array.

$response = array( "status" => true );

if(isset($_POST['type']))
    {
        if($_POST['type']=="booking"){
            $name = mysql_real_escape_string( $_POST ['Name'] ));    
            $mobile = mysql_real_escape_string($_POST ['Mob_Num']);
            $mail = mysql_real_escape_string($_POST ['Email']);               
            $query1 = "insert into customer(userName, userContactNumber, email) values('$name','$mobile','$mail')";
            $query2 = "insert into booking(cust_email, cust_mobile, cust_name) values('$mail','$mobile','$name')";          

            $result1 = mysql_query($query1);          
            $result2 = mysql_query($query2);
            $id = mysql_insert_id();

            $response["message"] = "Welcome Mr/Mrs ".$name."  Thanks for booking home services your booking id is =  ".$id;/* make sure you strip tags etc to prevent xss attack */

        }
    }
    else{
        $response["status"] = false;
        $response["message"] = "Invalid format";
    }

    echo json_encode($response);

    /* Note that you are making the query using ContentType:"application/json", */

which means you should respond using json regardless if query is successful or not. I would also recommend using a simple jQuery plugin called jStorage, that allows easy get/set of objects without having to serialize them.

Answer from Rainer Plumer on Stack Overflow
🌐
findnerd
findnerd.com › list › view › Sending-JSON-data-from-one-HTML-page-to-another-using-Session › 19350
Sending JSON data from one HTML page to another using Session
May 6, 2016 - $("button").click(function(){ var data = html2json(); storeuserdatainsession(data); window.location = 'slider.html'; });data variable contains the string value that is return by the html2json() function.here is the functionality of thehtml2json() ...
Top answer
1 of 3
1

If this is your real server side code then...its completely insecure. You should never pass variables posted by users directly into your queries.

$query2 = "insert into booking(cust_email, cust_mobile, cust_name) values('$mail','$mobile','$name')";  

At least escape the values using "mysql_real_escape_string", or use prepared statements. And...dont use mysql anymore, use mysqli, which is almost identical to what you are using, but not deprecated soon.

Also, you are json encoding a string that doesnt need to be json encoded, its just a piece of text and not valid json code. This may be why @SimarjeetSingh Panghlia answer doesnt work for you.

instead of json_encoding that value, encode a structured array.

$response = array( "status" => true );

if(isset($_POST['type']))
    {
        if($_POST['type']=="booking"){
            $name = mysql_real_escape_string( $_POST ['Name'] ));    
            $mobile = mysql_real_escape_string($_POST ['Mob_Num']);
            $mail = mysql_real_escape_string($_POST ['Email']);               
            $query1 = "insert into customer(userName, userContactNumber, email) values('$name','$mobile','$mail')";
            $query2 = "insert into booking(cust_email, cust_mobile, cust_name) values('$mail','$mobile','$name')";          

            $result1 = mysql_query($query1);          
            $result2 = mysql_query($query2);
            $id = mysql_insert_id();

            $response["message"] = "Welcome Mr/Mrs ".$name."  Thanks for booking home services your booking id is =  ".$id;/* make sure you strip tags etc to prevent xss attack */

        }
    }
    else{
        $response["status"] = false;
        $response["message"] = "Invalid format";
    }

    echo json_encode($response);

    /* Note that you are making the query using ContentType:"application/json", */

which means you should respond using json regardless if query is successful or not. I would also recommend using a simple jQuery plugin called jStorage, that allows easy get/set of objects without having to serialize them.

2 of 3
0

You can use sessionStorage to store and retrieve JSON Data.

var complexdata = [1, 2, 3, 4, 5, 6];

// store array data to the session storage
sessionStorage.setItem("list_data_key",  JSON.stringify(complexdata));

//Use JSON to retrieve the stored data and convert it 
var storedData = sessionStorage.getItem("complexdata");
if (storedData) {
  complexdata = JSON.parse(storedData);
}

To remove sessionStorage Datas after using use sessionStorage.clear();

🌐
Stack Overflow
stackoverflow.com › questions › 33910409 › pass-json-object-to-another-page
Pass JSON Object to another page - javascript
Broadly speaking JSON is nothing more than a regular javascript object. To store you just have to stringify it and store as string then when you want to treat this as object again you just parse it.
🌐
Stack Overflow
stackoverflow.com › questions › 22023844 › how-do-you-pass-json-data-from-one-page-to-another-to-reference-the-same-row-of
How do you pass json data from one page to another to reference the same row of data?
When you click on a button it then should open and populate the data for that location in a new page or if need into a dialog box. How do you pass the information to a new page and complete the if statement? Everything works great if I manually add the entry.id.$t string in the last if statement. $(document).ready(function () { $(function FISLocations() { $.getJSON("https://spreadsheets.google.com/feeds/list/GoogleSpreadsheetKey/od6/public/values? alt=json-in-script&callback=?", function (data) { $('.loc').append('<ul class="collapsibleList" id="list"><li><label for="mylist-node1" class="css_b
🌐
Stack Overflow
stackoverflow.com › questions › 19203598 › pass-json-from-one-html-to-other-html
Pass JSON from one html to other HTML
// Your /main.html file <script type="text/javascript"> w = window.open("/other.html", "WindowTitle"); function getJSON(){ return my_json_data; } </script> // Your /other.html file <script type="text/javascript"> // Get Json Data my_json_data ...
🌐
Stack Overflow
stackoverflow.com › questions › 41692239 › how-to-pass-json-data-into-query-string-and-use-that-data-in-another-page
how to pass json data into query string and use that data in another page
.state('initial', { url: 'some/initial', template: 'some/initial/template.html', params: { name: null, price: null, author: null, isbn: null, category: null } }) .state('read-book-details', { parent: 'initial', url: 'some/url', template: 'some/template.html', params: { name: null, price: null, author: null, isbn: null, category: null } }) Then when you're transitioning from one 'state' to another, you do it like so passing along the parameters you want: $state.go('read-book-details', { name: book.name, price: book.price, author: book.author }); On the 'other' page's controller (ie the controller for the 'read-book-details' state) you can inject $state and get the parameters that are passed in via $state.params (ie., $state.params.price)
Find elsewhere
🌐
Quora
quora.com › How-do-I-put-JSON-data-in-my-HTML-page
How to put JSON data in my HTML page - Quora
Answer (1 of 6): [code] $(function() { var people = []; $.getJSON('people.json', function(data) { $.each(data.person, function(i, f) { ...
🌐
Stack Overflow
stackoverflow.com › questions › 62136879 › how-to-get-json-data-in-one-another-page
How to Get json data in one another page?
June 1, 2020 - const data = JSON.parse(require('./data.json')); const url = new URL("http://view.html?id=02"); const { searchParams } = url; const userId = searchParams.get("id"); const userData = data.filter((user) => user.id === userId); // here you should ...
🌐
Medium
medium.com › @cyberbotmachines › how-to-pass-value-from-one-html-page-to-another-using-javascript-3c9ab62df4d
How To Pass Value From One HTML Page To Another Using JavaScript | by CyberBotMachines | Medium
October 10, 2024 - Here is how you turn string back to object: JSON.parse(myObjectString); ... And this is really all there is to passing value from one html page to another using JavaScript.
🌐
Stack Overflow
stackoverflow.com › questions › 43358028 › how-can-i-access-json-data-from-another-url-inside-a-html-page
php - how can I access json data from another url inside a html page - Stack Overflow
<script> $.ajax({ // name of file to call url: 'fetch_latlon.php', // method used to call server-side code, this could be GET or POST type: 'GET' // Optional - parameters to pass to server-side code data: { key1: 'value1', key2: 'value2', key3: 'value3' }, // return type of response from server-side code dataType: "json" // executes when AJAX call succeeds success: function(data) { // fetch lat/lon var lat = data.lat; var lon = data.lon; // show lat/lon in HTML $('#lat').text(lat); $('#lon').text(lon); }, // executes when AJAX call fails error: function() { // TODO: do error handling here console.log('An error has occurred while fetching lat/lon.'); } }); </script>
🌐
Stack Overflow
stackoverflow.com › questions › 13022800 › get-json-data-from-another-page-via-javascript
Get JSON data from another page via JavaScript - Stack Overflow
October 23, 2012 - function getDates() { jQuery(function($) { $.ajax( { url : "jsonPage.php", type : "GET", success : function(data) { // get the data string and convert it to a JSON object. var jsonData = JSON.parse(data); var date = new Array(); var i = -1; $.each(jsonData, function(Idx, Value) { $.each(Value, function(x, y) { if(x == 'date') { i = i + 1; date[i] = y; } }); }); //output my dates; [0] in this case $("#testArea").html(date[0]); } }); }); }
🌐
Ouseful Info
blog.ouseful.info › 2010 › 02 › 28 › grabbing-json-data-from-one-web-page-and-displaying-it-in-another
Grabbing JSON Data from One Web Page and Displaying it in Another
March 1, 2010 - If we want to display the serialsed version of the object in another page, rather than in an alert box or the browser console, we need to pass the the serialised object within the URI using an HTTP GET to the other page, so we can generate a ...
🌐
Stack Overflow
stackoverflow.com › questions › 43587968 › send-json-data-from-one-page-and-receive-dynamically-from-another-page-using-aja
Send JSON data from one page and receive dynamically from another page using AJAX when both page are open
June 8, 2017 - I am trying to send JSON data from page1 on submit button click and try to receive this data dynamically from page2 using AJAX and print the data in console. I don't know the proper syntax to do th...