larsrbak
larsrbak

Reputation: 105

AJAX script failing to put parameter

I have created a php script that I know works. I try communication to it with the following ajax call:

var request = new XMLHttpRequest();
request.open("GET", "http://larsbak.dk/schedule/GET/schedule.php");
request.setRequestHeader("Content-type", "application/json");
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
    data = JSON.parse(request.responseText);
}
request.send("id=201303560&interval=100000");

When i use the above script the server respons with error with error 104, which means that id parameter is not set. Why is this happening?

Upvotes: 0

Views: 29

Answers (1)

Quentin
Quentin

Reputation: 943537

  1. You are making a GET request, so you can't have a request body. Change that to "POST" or move the data to the query string.
  2. You are claiming you are sending "application/json", which "id=201303560&interval=100000" is not. You are sending "application/www-x-form-urlencoded" data.
  3. You forgot to end (}) your onreadystatechange handler

Upvotes: 3

Related Questions