0

My jquery code:

var jsonData;
$.ajax({
    url: 'http://mysite.lv/projects/addform',
    dataType: 'json',
    success: function(response) {
        jsonData = response;
        console.log('Works');
        }
});

My Controller function at http://mysite.lv/projects/addform:

$jsonData = array('x' => 'send x', 'y' => 'send y');
echo json_encode($jsonData);

In console:

GET http://mysite.lv/projects/addform 500 (Internal Server Error)

XHR finished loading: GET "http://mysite.lv/projects/addform".

Joel L
  • 3,031
  • 1
  • 20
  • 33
slc
  • 79
  • 8
  • What does your server's error log say? – Anthony Grist Jun 18 '14 at 10:41
  • Than the url is not existing or you are behind a firewall? Try to access the url directly via browser address line. And add following line to your php file: `header('Content-Type: application/json');` – algorhythm Jun 18 '14 at 10:41

1 Answers1

2

A 500 error means that your PHP script is failing.

The snippet you added is valid PHP, but the problem is likely elsewhere in the PHP code (or server configuration)

Try debugging by manually loading (that is, open it in your browser) your http://mysite.lv/projects/addform page and making sure it displays the data you expect.

Also enable PHP error reporting — see How to get useful error messages in PHP? here for details.

Community
  • 1
  • 1
Joel L
  • 3,031
  • 1
  • 20
  • 33