The following code triggers a GET instead of a POST HTTP request.
function AddToDatabase() {
this.url = './api/add';
}
AddToDatabase.prototype.postData = function(dataToPost) {
$.ajax({
type: "POST",
url: this.url,
data: dataToPost,
context: this,
success: this.onSuccess
});
};
var AddToDatabase = new AddToDatabase();
data = {data: 'coucou'};
AddToDatabase.postData(data);
Why, and how can I get a POST ?
I see in Google Chrome Inspect and Firefox Inspect that the browser sends a GET. Here is from Chrome:
Request URL:http://localhost/SAMPLE-CODES/UPDATE%20MYSQL/api/add/ Request Method:GET Status Code:200 OK
SOLVED
The URL called './api/add' was to actually post to './api/add/index.php'. Turns out that calling './api/add/index.php
' or './api/add/
' gives me a POST request.
It was just a wrong URL, but for some reason I was getting a successful GET request to '.api/add/'.