Monday, May 19, 2014

Json header and encode for PHP

link source: http://stackoverflow.com/questions/4064444/returning-json-from-a-php-script

PHP對JSON編碼後,送回去的資料型態利用header定義好再送回。
$data = array('a'=>array(1,2,3,4,5,6),'b'=>'bcd')/** whatever you're serializing **/;
header('Content-Type: application/json');
echo json_encode($data);

Tuesday, May 13, 2014

Same-origin policy fro javascript

同源政策,cross browser ajax的處理方式

1. put below in your .php file 


2.use jsonp as following
$.ajax({
 url: 'http://....................,
 crossDomain: true,
 dataType: 'jsonp',
 data:{
  uname: $('input#A1').val(),
  uphone: $('input#A2').val(),
  uemail: $('input#A3').val(),
  callback: json_callback
 }
}).done(function(data){
});