Native JSON can access JSON data in local, how to access JSON data in external domain with Jquery/ Jquery Mobile
The answer is JSONP , P= Padding, it's not feature but it's only technique, ok let's start from your JSON data ,
1) CREATE PHP PAGE FOR JSON WEB SERVICE
get_short.php
<?php require_once('Connections/conntesjsonp.php'); ?>
$mycallback = $_GET['callback']; // used for JSONP callback
mysql_select_db($database_connDro, $connDro);
$query_rsdrod = "SELECT iduser, shortprofile, nmbisnis,userlogo FROM tbuser";
$rsdrod = mysql_query($query_rsdrod, $connDro) or die(mysql_error());
//$row_rsdrod = mysql_fetch_assoc($rsdrod);
$totalRows_rsdrod = mysql_num_rows($rsdrod);
?>
<?
//create JSON format
$rows = array("short" => array());
while($row_rsdrod = mysql_fetch_assoc($rsdrod))
{
$rows["short"][] = $row_rsdrod;
}
echo $mycallback."(".json_encode($rows).")";
?>
<?php
mysql_free_result($rsdrod);
?>
2) CREATE HTML PAGE TO LOAD JSON
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Try JSON with SISINDOTEK Solution</title>
<script src="jquery-mobile/jquery-1.11.0.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(e) {
getshort();
});
function getshort() {
$.getJSON("http://sisindotek.com/jsonservice/get_short.php?id=purnama&callback=?",
function (data) {
$('#listshort li').remove();
varShort = data.short;
$.each(varShort, function(index, sshort) {
$('#listshort').append('<li><h2>'+sshort.shortprofile +
'</h2>' );
});
$('#listshort').listview('refresh');
});
}
</script>
</head>
<body>
<div id="testload">
<ul id="listshort">
</ul>
loding</div>
</body>
</html>
THAT'S IT , SIMPLE RIGHT HOW TO USE JSONP TO ACCESS EXTERNAL DOMAIN JSON DATA
SISINDOTEK - IT Training & Solution Provider
Jl. Sukasenang VI-6B Bandung - Jawa Barat 40124
Tel. 022-92953577, SMS. 0812.8733.1966
info , YM. sisindotek
www.sisindotek.com , facebook.com/sisindotek , twitter.com/sisindotek
The answer is JSONP , P= Padding, it's not feature but it's only technique, ok let's start from your JSON data ,
1) CREATE PHP PAGE FOR JSON WEB SERVICE
get_short.php
<?php require_once('Connections/conntesjsonp.php'); ?>
$mycallback = $_GET['callback']; // used for JSONP callback
mysql_select_db($database_connDro, $connDro);
$query_rsdrod = "SELECT iduser, shortprofile, nmbisnis,userlogo FROM tbuser";
$rsdrod = mysql_query($query_rsdrod, $connDro) or die(mysql_error());
//$row_rsdrod = mysql_fetch_assoc($rsdrod);
$totalRows_rsdrod = mysql_num_rows($rsdrod);
?>
<?
//create JSON format
$rows = array("short" => array());
while($row_rsdrod = mysql_fetch_assoc($rsdrod))
{
$rows["short"][] = $row_rsdrod;
}
echo $mycallback."(".json_encode($rows).")";
?>
<?php
mysql_free_result($rsdrod);
?>
2) CREATE HTML PAGE TO LOAD JSON
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Try JSON with SISINDOTEK Solution</title>
<script src="jquery-mobile/jquery-1.11.0.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(e) {
getshort();
});
function getshort() {
$.getJSON("http://sisindotek.com/jsonservice/get_short.php?id=purnama&callback=?",
function (data) {
$('#listshort li').remove();
varShort = data.short;
$.each(varShort, function(index, sshort) {
$('#listshort').append('<li><h2>'+sshort.shortprofile +
'</h2>' );
});
$('#listshort').listview('refresh');
});
}
</script>
</head>
<body>
<div id="testload">
<ul id="listshort">
</ul>
loding</div>
</body>
</html>
THAT'S IT , SIMPLE RIGHT HOW TO USE JSONP TO ACCESS EXTERNAL DOMAIN JSON DATA
SISINDOTEK - IT Training & Solution Provider
Jl. Sukasenang VI-6B Bandung - Jawa Barat 40124
Tel. 022-92953577, SMS. 0812.8733.1966
info , YM. sisindotek
www.sisindotek.com , facebook.com/sisindotek , twitter.com/sisindotek
Oh my goodness! Incredible article dude! Thank you, However I am having issues with your RSS.
ReplyDeleteI don't know the reason why I cannot join it.
Is there anybody else having similar RSS issues? Anyone who knows the solution can you kindly respond?
Thanks!!