buat funtion dulu y,... some function
=============
public function test_api(){
header('Content-type: application/json');
// header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
//header( 'Access-Control-Allow-Headers: Authorization, Content-Type' );
header('Access-Control-Allow-Origin: *');
$json['msg'] = 'ok';
echo json_encode($json);
//echo json_encode(array("mmm"=>"ll"));
}
=============
to call ajax di view nya
============
<div>
<button id="click">click</button>
</div>
<script type='text/javascript'>
// $(function(){
// alert(123);
// $('#click').on('click',function(){
// $.ajax({
// url:'http://192.168.3.28/ci-api-test/index.php/welcome/test_api',
// data:'data',
// dataType:'json',
// type:'post',
// success:function(res){
// alert('res.msg')
// }
// })
// })
// })
$(document).ready(function(){
$('#click').click(function(){
//alert('ok ssss');
//http://192.168.3.28/ci-api-test/index.php/welcome/test_api
// $.get('http://192.168.3.28/ci-api-test/index.php/welcome/test_api',function(res){
// alert(res.msg)
// })
// $.ajax({
// type: "GET",
// url: 'http://192.168.3.28/ci-api-test/index.php/welcome/test_api',
// //data:{q:idiom},
// async:true,
// dataType : 'jsonp', //you may use jsonp for cross origin request
// crossDomain:true,
// success: function(res) {
// //alert(xhr.getResponseHeader('Location'));
// alert(123);
// //alert(res.msg);
// }
// });
// $.ajax({
// type: 'GET',
// //url: 'http://xxx.amazonaws.com/file.json',
// url: 'http://192.168.3.28/ci-api-test/index.php/welcome/test_api',
// dataType: 'jsonp',
// jsonpCallback: 'callback',
// success: function(json){
// console.log(json)
// }
// })
// var url = "http://someremoteurl.com/json";
// $.getJSON(url + "?callback=?", null, function(data) {
// callBackFunction(data);
// });
$.ajax({
type: "GET",
//url: 'http://192.168.3.28/ci-api-test/index.php/welcome/test_api',
url: 'http://192.168.3.32/ci-api-test/index.php/welcome/test_api',
//data:{q:idiom},
async:true,
dataType : 'json', //you may use jsonp for cross origin request
crossDomain:true,
success: function(res) {
//alert(xhr.getResponseHeader('Location'));
//alert(123);
alert(res.msg);
}
});
})
// function callBackFunction(data)
// {
// alert(123);
// console.log(data);
// }
})
</script>
============
selamat belajar
Langganan:
Posting Komentar (Atom)
0 Response to "crossing universe system codeigniter"
Posting Komentar