I create a short example of POST
var p = {Name: obj.Name, Age: obj.Age},
str = JSON.stringify(p);
$.post("test.php", str, function (data) {
alert("Post finished");
}).success(function () {
alert("second success");
}).error(function() {
alert("error");
});
When I run above code, It throws an error message of 404 not found from test.php.
I created this file test.php in my project.
Why am I getting this error?
The first parameter in
postmethod is theurlthat you would want to send thepost data.HTTP 404means that url given is not found in the server.Since there is no
test.phpthat would receive your data, you will get this error.You should create a
test.phpfile that you accept your request.Another thing is, you don’t need to
stringifyJSON object while sending it to the server,jqueryhandles this automatically. Just send theobjaspost data.