Gerard Anthony McBride Gerard Anthony McBride - 1 year ago 107
Javascript Question

PUT/POST request sending without data

I have a client which makes the following request to a Pyramid Service.

var sendArr = {"hello": "world"};
$.ajax({
type: "PUT",
contentType: "application/json",
url: "http://0.0.0.0:6543/" + obj.id + newUrlSegment,
data: sendArr,
headers: { 'X-User-Email': loggedUser.user, "X-Auth-Token": loggedUser.token},
success: function(data,status,other){
console.log("server return", data);
},
error: function (XMLHttpRequest, textStatus, errorThrown){
console.log(errorThrown);
},
});


The request is received by the server, however the request 'data' is missing.

Is there any particular reason why the data is not being attached client-side?

Answer Source

If you use:

data: JSON.stringify(sendArr)

It should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download