Showing posts with label json. Show all posts
Showing posts with label json. Show all posts

Tuesday, 23 October 2012

How to pass data from one domain to another domain(cross domain) using json?‏

//Javascript code

<script type="text/javascript">

$(document).ready(function()
{

var surl =  "http://www.example.com/json.php";

email_id=document.getElementById("email").value;

$.ajax({
url: surl,
data: {email:email_id},
dataType: "jsonp",
jsonp : "callback",
jsonpCallback: "jsonpcallback"
});
});

function jsonpcallback(rtndata)
{
document.getElementById("disp_data").innerHTML=rtndata.message;
}

</script>

//json.php file code

<?php

$display="<b>HI Json</b>";

$display.="<p>HI This is testing json.</p>";

$rtnjsonobj->message = $display;

echo $_GET['callback']. '('. json_encode($rtnjsonobj) . ')';

?>