As of now I am not using authentication for Tastypie but I am able to see content, when I go to url in browser.
http://localhost:8000/live/api/update/?format=json
but I am trying to get this data in the page via an jquery ajax call,
$.post('/live/api/update/?format=json',
{type:'GET',dataType: "json", processData: false,
contentType: "application/json",userid:$('#index').val()},function(devicelist){
.....
}
In browser firebug console, I m seeing a 401
Note : from Haris's Answer, I was able to solve the issue, but I want why it works
when I use
$.ajax({ type: "POST", url: url, data: data, success: success, dataType: dataType });
it is working(Status:202) whereas when I use
$.post('/live/api/update/?format=json',
{type:'GET',dataType: "json", processData: false,
contentType: "application/json",userid:$('#index').val()},function(devicelist){
.....
}
this is not working.Actually I shifted my PHP code to Django, when I used PHP the above code used to work with 401 error
There is no Authentication in tastypie api code
api.py
from tastypie.resources import ModelResource
from models import Update
from tastypie.serializers import Serializer
import urlparse
class urlencodeSerializer(Serializer):
formats = ['json', 'jsonp', 'xml', 'yaml', 'html', 'plist', 'urlencode']
....
class UpdateResource(ModelResource):
class Meta :
queryset = Update.objects.all()
resource_name = 'update'
filtering = {'imei' : ALL }
#authentication = DjangoCookieBasicAuthentication()
serializer = urlencodeSerializer() # IMPORTANT
allowed_methods = ['get','post']