views:

55

answers:

3

Hi,

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"&gt;
</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

A: 

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

Yosef
Perhaps you could add a bit more detail, e.g. what the problem was/how it was fixed--in case someone else getting 503 errors during their AJAX requests stumbles on this page.
Lèse majesté
+1  A: 

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

Lizard
+1  A: 

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');
Aaron Harun