I'm trying to send data to a php file on my server. This is the inside of a function called send(message)
. I've already used this method to successfully send and receive other data. When I try to use the same method with a different message, it immediately fails with textStatus="error"
and errorThrown=""
.
alert(JSON.stringify(message));
$.ajax({
type: 'POST',
cache: false,
url: '/web_db_service.php',
data: JSON.stringify(message),
dataType: 'text',
success: doneCallback
}).fail(function(jqXHR, textStatus, errorThrown) {
alert("Fail " + textStatus + ": " + errorThrown);
doneCallback(null);
}).always(function(jqXHR, textStatus, errorThrown) {
alert("Always " + textStatus + ": " + JSON.stringify(errorThrown));
});
The alert at the beginning of the method displays this:
{
"method":"write",
"className":"Account",
"id":"test@test.com",
"object":"
{
\"id\":\"test@test.com\",
\"password\":\"hashedpw\",
\"first\":\"Tester\",
\"last\":\"Testing\",
\"zip\":\"78945\",
\"phone\":\"11231234\",
\"children\":
[
{
\"id\":null,
\"first\":\"Child\",
\"middle\":null,
\"last\":\"Person\",
\"interests\":[]
}
]
}
}
I think it has to do with the formation of the data that's being passed, but I don't know what it is. The php file simply echos the data that's passed to it right now, which again is working for a different, simpler message.
EDIT: The problem turned out to be that I was changing the window too soon, without waiting for the message to send and come back.