Created
November 1, 2019 15:12
-
-
Save Kcko/19fa5c86fa4dab08a2fe4bb93d4c98d5 to your computer and use it in GitHub Desktop.
This file contains 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
<IfModule mod_headers.c> | |
Header set Access-Control-Allow-Origin "*" | |
</IfModule> | |
# Header add Access-Control-Allow-Origin "http://my-domain.com" |
This file contains 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"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js'></script> | |
</head> | |
<body> | |
<!-- https://www.sitepoint.com/jsonp-examples/ --> | |
<div style="background: goldenrod; padding: 1rem;"> | |
<script src="http://lab.rjwebdesign.cz/jsonp/js.php"></script> | |
</div> | |
<div style="background: burlywood; padding: 1rem;" id="jsonp"> | |
</div> | |
<script> | |
// 1 zpusob | |
$.getJSON('http://lab.rjwebdesign.cz/jsonp/jsonp.php?callback=?', function(json){ | |
console.log(json); | |
}); | |
// 2 zpusob | |
function logResults(json) { | |
console.log(json); | |
} | |
$.ajax({ | |
url: "http://lab.rjwebdesign.cz/jsonp/jsonp.php", | |
dataType: "jsonp", | |
jsonpCallback: "logResults" | |
}); | |
</script> | |
</body> | |
</html> |
This file contains 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
<?php | |
header("content-type: application/x-javascript"); | |
$html = 'user is Kcko , job: developer'; | |
$html = replace_newline($html); | |
$html = str_replace("'", "\"", $html); | |
function replace_newline($string) { | |
return (string)str_replace(array("\r", "\r\n", "\n"), '', $string); | |
} | |
?> | |
document.write('<?= $html ?>'); | |
This file contains 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
<?php | |
header('Content-Type: text/html; charset=utf-8'); | |
function replace_newline($string) { | |
return (string)str_replace(array("\r", "\r\n", "\n"), '', $string); | |
} | |
$html = array('user' => 'Kcko', 'position' => 'developer'); | |
$html = json_encode($html); | |
echo $_GET['callback'] . '(' .$html . ');'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment