9-bits
9-bits

Reputation: 10775

ajax put is returning 500 internal server error

I'm using django tastypie to implement a REST api but am running into a problem i can't figure out:

When I run a curl

curl -H "Content-Type: application/json" -X PUT --data '{"title": "my video", "date_created": "2007-03-07T14:48:22"}' http://localhost:8080/api/v1/video/1/

This works and changes the content as expected.

However when I try to do this through the browser with a call like:

 $.ajax({
    url: 'http://localhost:8080/api/v1/video/1/',
    type: 'PUT',
    data: JSON.stringify(mydata),
    success: check,
    dataType: 'text/html',
    error: function(jqXHR, textStatus, errorThrown) {
      alert(textStatus);
    },
});

I get a 500 Internal Server Error

I have no idea why this is....is this because browsers no longer support PUT? What's the proper work around?

Upvotes: 2

Views: 2997

Answers (1)

Cyclonecode
Cyclonecode

Reputation: 30071

I think you are using the incorrect dataType, try using jsonp. May also be browser specific, from jQuery:

The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

This link may also be useful: jquery - how to put json via ajax

Upvotes: 0

Related Questions