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:
- <?php
- if ($_POST["id"] != null) {
- $response = "Hello " . $_POST["id"];
- }
- else {
- $response = "Unknown ID";
- }
- echo $response;
- ?>
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
- .post("http://localhost:8080/testscript.php",{ "id": "5" }, function (response) {
- var data = response
- if (data == null) {
- alert ("Error encountered")
- }
- else { alert ("Message: " + data)
- }
- } // function (response)
- );