Created
July 11, 2018 06:35
-
-
Save ahgood/85b02d339ffe6f3cf9b09e30745e6645 to your computer and use it in GitHub Desktop.
PHP + jQuery JSONP Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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