I have to pass Json data which is generated after inserting the info into datbase table, Now I have to pass this info to other page BookingConformation.html.
For example we will get the form server Welcome Mr/Mrs Mittel Thanks for booking home services your booking id is 1. So please tell me how to pass info which is get form server in javascript now I have to pass this info to other page, please help me on this.
script
<script>
$(document).ready(function(){
$("#register-form").validate({
rules: {
userName: "required",
email: {
required: true,
email: true
},
userContactNumber: "required"
},
messages: {
userName: "Please enter your Name",
userContactNumber: "Please enter your Mobile number",
email: "Please enter a valid email address",
},
submitHandler: function(form) {
var uName = $('#userName').val();
var mailId = $('#email').val();
var mobNum = $('#userContactNumber').val();
$.ajax({
url:"http://localhost/bookRoom/book.php",
type:"POST",
dataType:"json",
data:{type:"booking", Name:uName, Email:mailId, Mob_Num:mobNum},
ContentType:"application/json",
success: function(response){
//alert(JSON.stringify(response));
//alert("success");
alert(response);
var globalarray = [];
globalarray.push(response);
window.localStorage.setItem("globalarray", JSON.stringify(globalarray));
window.location.href = 'BookingConformation.html';
},
error: function(err){
window.location.href = 'error.html';
}
});
return false; // block regular submit
}
});
});
</script>
server code
<?php
header('Access-Control-Allow-Origin: *');//Should work in Cross Domaim ajax Calling request
mysql_connect("localhost","root","7128");
mysql_select_db("service");
if(isset($_POST['type']))
{
if($_POST['type']=="booking"){
$name = $_POST ['Name'];
$mobile = $_POST ['Mob_Num'];
$mail = $_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();
$value = "Welcome Mr/Mrs ".$name." Thanks for booking home services your booking id is = ".$id;
echo json_encode($value);
}
}
else{
echo "Invalid format";
}
?>
BookingConformation.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function myFunction() {
var globalarray = [];
var arrLinks =[];
arrLinks = JSON.parse(window.localStorage.getItem("globalarray"));
document.getElementById("booking").innerHTML = arrLinks;
}
</script>
</head>
<body>
<p id="booking" onclick="myFunction()">Click me to change my HTML content (innerHTML).</p>
</bod
y>