1:跨域访问
Html
<!DOCTYPE html5>
<html>
<head>
<title>jQuery</title>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<style>
body, html { margin:0; padding: 0; overflow:hidden }
</style>
<script>
$(document).ready(function() {
});
function ajaxdo(){
var json_data = {"type": 'you_type'};
// async: false,
// jsonp: 'jsoncallback',
$.ajax({
type:"get",
data: json_data,
url: 'http://192.168.1.192/test/ajax_respone.php?jsoncallback=?',
timeout: 30000,
dataType : "json",
success: function(result){
console.log(result.name);
console.log(result.type);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus);
}
});
}
</script>
</head>
<body>
<input type="button" οnclick="ajaxdo();" value="OK"/>
</body>
</html>
ajax_respone.php
<?php
$jsoncallback = $_GET['jsoncallback'];
$log_type = $_GET['type'];
$result_json['name'] = 'john';
$result_json['type'] = $log_type;
$json = json_encode($result_json);
echo $jsoncallback.'('.$json.')';
?>