Skip to content

Instantly share code, notes, and snippets.

@ahgood
Created July 11, 2018 06:35
Show Gist options
  • Save ahgood/85b02d339ffe6f3cf9b09e30745e6645 to your computer and use it in GitHub Desktop.
Save ahgood/85b02d339ffe6f3cf9b09e30745e6645 to your computer and use it in GitHub Desktop.
PHP + jQuery JSONP Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="jquery-3.2.1.min.js"></script>
<script>
jQuery.ajax({
url: "jsonp.php",
dataType: "jsonp",
jsonpCallback: "callback",
success: function(data){
console.log(data[0]);
}
});
</script>
</body>
</html>
<?php
$data = array("foo", "bar", "hello", "world");
$data = json_encode($data);
echo "callback($data)";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment