Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Why ajax HTTP POST gets an empty response from server?

I am trying to do a POST request in ajax in this way:

$.ajax({
                type: "POST",
                url: 'http://192.168.1.140/',
                data: "{}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                   alert(data);
                },
                error: function (data, success, failure) {
                    alert("Error:" + failure);
                }
            });

The server I have at that IP only do this:

<?php
echo "test"
?>

In the alert I only get the word 'Error' from the error function and nothing else from the parameters. I don't know where is the problem. I want it to display in the alert the word 'test' that the servers sends. Can anyone tell me what I am doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The reason you're getting an error is because you're telling jQuery ajax that this request will return a json response but you just return plain text.

I'm not sure why your errorThrown is blank as it should show parse error.
You can just have alert("Error:" + data.responseText); to alert the result.

To avoid the error you can echo json in your php script echo '{"test":true}'
or remove the dataType: "json", in your request.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!