开发者

Json code retrieved with AJAX is unparsable

I'm a beginner.

I write simple json jquery php code to help understand the idea of json, but its not work, please help me.(I didnt write $_Post, submit, click function etc.. because its not working with, soo I cut the code to find the problem)

The user enters view.html and should get an alert box with value Bob - the problem is the user doesn'开发者_运维知识库t get the alert box.

view.html

<html>
<head>
<script type="text/javascript" 
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
  $(document).ready(function () {
      $.ajax({
          url: 'controller.php',
          type: 'post',
          dataType: 'json',
          success: function (data) {
              alert(data["userdata"]["first"]);
          }
      });
  });​
</script>
</head>
<body>
</body>
</html>

controller.php:

<?php
  $arr=array();
  $arr['userdata']['first']='Dan';
  echo json_encode($arr);
?>

Thanks for help


You will to check your apache's mod_security settings. This could be causing your 503 Service Temporarily Unavailable


Try adding the correct JSON header to your PHP file.

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');


Thank to Jan I find the problem: my local zend server not worked (because i didnt define password for zend community server) when i fix it its starts working

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜