jquery - Django tastypie XMLHttpRequest cannot load -
i have been reading xmlhttprequest past hour, can seem make work.. so, have django server tastypie , javascript client on server/port, , when try jquery post
xmlhttprequest cannot load http://127.0.0.1:8000/api/smart/rating/. origin http://localhost not allowed access-control-allow-origin.
i xmlthhprequest error message on 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 localhost:80 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 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 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 doing wrong?
hi think making cross origin request.
to initiate cross-origin request, browser sends request origin http header. value of header site served page.
to allows request, sends access-control-allow-origin header in response. value of header indicates origin sites allowed.
access-control-allow-origin: localhost:80
essentially need allow options request on server side sends access-control-allow-origin header
please go through better idea
cross domain post query using cross-origin resource sharing getting no data back
Comments
Post a Comment