PHP Classes

File: javascript/jsonp.php

Recommend this page to a friend!
  Classes of Kabir Hossain   PHP CodeIgniter Tips Tricks   javascript/jsonp.php   Download  
File: javascript/jsonp.php
Role: Auxiliary script
Content type: text/plain
Description: Configuration script
Class: PHP CodeIgniter Tips Tricks
Collection of tips and examples to use CodeIgniter
Author: By
Last change:
Date: 1 month ago
Size: 838 bytes
 

Contents

Class file image Download
<?php
$firstname
= isset($_GET['firstname']) ? $_GET['firstname'] : '';
if (
$firstname == 'Jeff') {
 
header("Content-Type: application/json");
 
$data = array('fullname' => 'Jeff Hansen', 'message' => '\a aaâ " ^><*&@ { })( ;');
 
//echo $_GET['callback'] . '(' . "{'fullname' : 'Jeff Hansen'}" . ')';
 
echo $_GET['callback'] . '(' . json_encode($data) . ')';
  exit;
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>jsonp example</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
      $.getJSON('./jsonp.php?callback=?', 'firstname=Jeff', function(res) {
        alert('Your name is ' + res.fullname);
        alert('Bullshit data is: ' + res.message);
      });
    </script>
  </head>
  <body>
  </body>
</html>