String Response from PHP received by .post() as [object Object]

String Response from PHP received by .post() as [object Object]

I hope someone can help me out here. I have a jquery script which sends a POST request and a simple PHP file which does the following:
  1. <?php
  2. if ($_POST["id"] != null)  {
  3. $response = "Hello " . $_POST["id"];
  4. }
  5. else {
  6. $response = "Unknown ID";
  7. }
  8. echo $response;
  9. ?>
The jQuery .post function is suppose to prompt the user with the response from the server but the alert prompt only shows [object Object]. Does anyone know what's wrong?

Here's a simple version of the post() function
  1. .post("http://localhost:8080/testscript.php",{ "id": "5" }, function (response) {
  2. var data = response
  3. if (data == null) {
  4. alert ("Error encountered")
  5. }
  6. else { alert ("Message: " + data)
  7. }
  8. } // function (response)
  9. );