Human Cyborg Relations
Human Cyborg Relations

Reputation: 1244

Send a success response to POST request

I've got the following ajax call:

function sendRequest(quote, author){
    $.ajax({
        type: "POST",
        url: window.location.pathname,
        data: {quote: quote, author: author},
        dataType: JSON,
        success: function(){console.log("Data sent!");},
        error: function(error){console.log("ran into an error")}
    });
}

And here is my server (using express) handling the post request,

app.post("/", function(req, res){res.status(200).end("Success!")});

However, the console doesn't print "Data Sent". Instead, it prints "ran into an error"

Everything else is tested and is working correctly

Upvotes: 0

Views: 1766

Answers (1)

Ghost Developer
Ghost Developer

Reputation: 1433

First of all dataType should be 'json' not JSON

Then check the console log for specific error.

Upvotes: 1

Related Questions