i have been reading about XMLHttpRequest for the past hour, but i can seem to make this work.. So, i have a django server with tastypie and a JavaScript client on another server/port, and when i try to do a jquery post i get a
XMLHttpRequest cannot load http://127.0.0.1:8000/api/smart/rating/. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
I get Xmlthhprequest error message on the client-side
Django code:
class RatingResource(ModelResource):
city = fields.ForeignKey(CityResource, 'city')
user = fields.ForeignKey(UserResource, 'user')
class Meta:
queryset = Rating.objects.all()
resource_name = 'rating'
#authentication = BasicAuthentication()
#authorization = DjangoAuthorization()
My jquery call posting from localhost:80 to localhost:8000:
$('#star').raty({
path: "../assets/img/",
score : rating,
click : function(score, evt) {
window.rate_app = score;
var url = "http://127.0.0.1:8000/api/smart/rating/";
//var comment = $('#textarea').val();
var comment = "teste do php";
console.log(cityId);
$.post(url,{city : '/api/smart/city/'+cityId+'/' ,comment : comment,id:'4',resource_uri:'/api/smart/rating/4/',rating : score, user: '/api/smart/auth/user/2/'},function(data,status){
if (data=="error")
console.log("error");
else
console.log("success");
});
}
});
UPDATE:
HTTP/1.0 401 UNAUTHORIZED
curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"city": "/api/smart/city/35/", "comment": "teste do php", "id": "4", "resource_uri": "/api/smart/rating/4/", "rating": "3","user_id": "/api/smart/auth/user/2/"}' `http://localhost:8000/api/smart/rating/`
HTTP/1.0 401 UNAUTHORIZED
Date: Mon, 08 Apr 2013 10:52:44 GMT
Server: WSGIServer/0.1 Python/2.7.3
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE
Content-Type: text/html; charset=utf-8
Access-Control-Allow-Headers: Content-Type,*
Access-Control-Allow-Credentials: true
what am i doing wrong?