Skip to main content

How To use JSONP with getJSON Jquery across external domain

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

Comments

  1. Oh my goodness! Incredible article dude! Thank you, However I am having issues with your RSS.
    I 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!!

    ReplyDelete

Post a Comment

Silahkan isi komentar atau iklan baris Anda, Jangan lupa visit social media kami di FB/Twitter/Instagram @alamatclick

Popular posts from this blog

Training PHP JQuery bersama PT.GSP bandung

Terima kasih kami ucapkan kepada peserta dari PT . GSP Bandung yang telah mengikuti Training PHP JQuery di SISINDOTEK Bandung Salam, SISINDOTEK - IT Training & Solution Provider Jl. Sukasenang VI-6B Bandung - Jawa Barat 40124 Tel. 022-71242266 , SMS. 0812.8733.1966 info , YM. sisindotek www.sisindotek.com , facebook.com/sisindotek , twitter.com/sisindotek

Training MS Project Secara Online - Hery Purnama

Home  » » Training Online Microsoft Project dan VBA Macro - Hery Purnama Training Online Microsoft Project dan VBA Macro - Hery Purnama 9:24 AM       No comments Mau tetap bisa training MS Project bersama Hery Purnama ditengah masa Panedemi COVID-19, tidak usah khawatir kini saya membuka kelas webinar  MS Project dan Excel VBA Macro (Senin-Sabtu) dengan 3 slot waktu 09.00-11.30 , 13.00 - 15.30 , 19.30 - 22.00 , book sekarang karena peminat sangat banyak sampai saat ini, hubungi 081-223344-506 Regards, HERY PURNAMA Certified IT Trainer http://www.inhousetrainer.net E-mail :  inhousetrainer@yahoo.com ,  hery.purnama@gmail.com  Call/ SMS/WA :  081.223344.506 , BBM : 7DC633AA      Social Net :   facebook.com/inhousetrainer   twitter.com/inhousetrainer   instagram.com/inhousetrainer Hometown : Bandung - Jawa Barat

WHAT IS COBIT ISACA

What is COBIT? COBIT stands for Control Objectives for Information and Related Technology. It is a framework  created by the ISACA (Information Systems Audit and Control Association). It was designed to be a  supportive tool for managers—and allows bridging the crucial gap between technical issues,  business risks, and control requirements. COBIT is a thoroughly recognized guideline that can be applied to any organization in any  industry. Overall, COBIT ensures quality, control, and reliability of information systems in an  organization, which is also the most important aspect of every modern business. Cybersecurity Expert Master's Program Master the Skills of a Cybersecurity ProfessionalVIEW COURSECybersecurity Expert Master's Program What is ISACA? ISACA stands for Information Systems Audit and Control Association. It develops controls and  guidance for information governance, security, control, and audit professionals. This i...