If you are using Jquery Ajax to call to a remote url, your code will maybe generate an error like this “Access to restricted URI denied” code: “1012″ or “Permission Denied …”
To solve this problem, Jquery now supports JSONP natively, you will load JSON from a remote url then an extra callback will be provided for the server to interpret.
JSONP is a technique that allows you to transfer JSON data across multiple domains.
Below is a very simple demo illustrate how to call to a remote url using Jquery Ajax Jsonp:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<title>rapid-DEV.net Jquery Ajax JSON Cross Domain Example</title>
</head>
<script>
jQuery(document).ready(function(){
jQuery("#btn").click(function(){
var dataString = "Name=" + jQuery("#txtName").val() + "&&Message=" + jQuery("#txtMessage").val();
var url = "http://rapid-dev.net/demo/json_process.php?" + dataString;
$.getJSON(url + "&jsoncallback=?", function(data){
Name = data.Name;
Message = data.Message;
if(Name != "" && Message != "")
{
jQuery("#td_msg").html("Hello " + Name + ", you typed: " + Message);
}
else
{
jQuery("#td_msg").html("Please enter Name and Message to get the result!!!");
}
})
return false;
});
});
</script>
<body>
<table cellspacing="0" cellpadding="2" border="0" width="30%" align="center">
<tbody>
<tr><td colspan="2" style="color:red" id="td_msg"></td></tr>
<tr><td colspan="2"><h3>Jquery Ajax JSON Cross Domain Example</h3></td></tr>
<tr>
<td align="left">Your name: </td>
<td align="left"><input type="text" name="txtName" id="txtName"/></td>
</tr>
<tr>
<td align="left">Type something: </td>
<td align="left"><input type="text" name="txtMessage" id="txtMessage" /></td>
</tr>
<tr>
<td></td>
<td align="left"><input type="button" id="btn" name="btn" value="Submit" /></td>
</tr>
</tbody>
</table>
</body>
</html>
PHP Process Page:
<?php
$Name = $_GET["Name"];
$Message = $_GET["Message"];
echo $_GET["jsoncallback"] . "({"Name": "" . $Name . "", "Message": "" . $Message . ""})";
?>
Click here to view online demo.
Download the source code: rd-jquery-ajax-json-cross-domains
Related Stuff
-
MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.
-
Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone
-
TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support
-
ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.
-
Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.
-
Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software
- PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Original Source: