Kod
<?php
header('content-type: application/json; charset=utf-8');
$searchResults= array("Article 1", "Article 2", "Article 3");
echo $_GET['callback'] . '('.json_encode($searchResults).')';
?>
header('content-type: application/json; charset=utf-8');
$searchResults= array("Article 1", "Article 2", "Article 3");
echo $_GET['callback'] . '('.json_encode($searchResults).')';
?>
example.js
Kod
(function() {
main();
function main() {
jQuery(document).ready(function($) {
$.ajax({
type: 'post',
dataType: 'jsonp',
crossDomain: true, // Shouldent be neccesary.
url: 'http://example.com/search.php',
data: { value: '123' },
cache: false,
success: function(returndata) {
$('#widget').html(returndata);
}
});
});
}
})();
main();
function main() {
jQuery(document).ready(function($) {
$.ajax({
type: 'post',
dataType: 'jsonp',
crossDomain: true, // Shouldent be neccesary.
url: 'http://example.com/search.php',
data: { value: '123' },
cache: false,
success: function(returndata) {
$('#widget').html(returndata);
}
});
});
}
})();
Kod
<script src="http://example.com/widget.js" type="text/javascript"></script>
<div id="widget" data-value="562"></div>
<div id="widget" data-value="562"></div>
Jak mogę pobrać i przesłać do search.php wartosc data-value z #widget?