后台代码:

  1. function ajax()
  2. {
  3. header('Access-Control-Allow-Origin:*');
  4. $data['test'] = "this is test..";
  5. $data['aaa'] = $_POST['aaa'];
  6. $callback = $_POST['callback'];
  7. echo $callback.'('.json_encode($data).')';
  8. exit;
  9. }

前端代码:

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>test</title>
  6. <!-- <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script> -->
  7. <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
  8. </head>
  9. <body>
  10. </body>
  11. <script type="text/javascript">
  12. $.ajax({
  13. type : "POST",
  14. async:false,
  15. url : "http://biz.live.com/caller?c=alipay&a=ajax",
  16. data: {aaa: 'ttaaatatata', callback:'callback'},
  17. success : function(json){
  18. alert(json);
  19. },
  20. error:function(){
  21. alert('fail');
  22. }
  23. });
  24. </script>
  25. </html>

分类: web

标签:   php