json output and .getJSON problem

30 views
Skip to first unread message

Wayne

unread,
May 16, 2010, 11:10:58 AM5/16/10
to django-piston
Hi,

I am very new to Django-piston and JQuery library. For my project, I
set up an api application which outputs data in the JSON format. When
I try to access it with the following code:
var url1 = "myURL"
$.getJSON(url1, function(data){
if(data.length){
//do something
}
});

it could not read the data. When I change myURL to:
http://search.yahooapis.com/ImageSearchService/V1/imageSearch?appid=YahooDemo&query=Madonna&output=json

this code works. So I am wondering if anybody could help me out on
this.

One difference I notice is that When I access my api using Firefox
directly,
I always trigger download mode with a user-prompt asking me this: "
You have chosen to open, which is a : application/json ..., what
should Firefox do with this file?...". And then Firefox downloads the
file
and displays it as a ***.part file (getJSON can read this file so it
should contain the valid json format.). However when I access the
yahoo apis using the browser, the data files can be opened directly in
the browser without the prompt. I don't know whether this would be the
cause of my problem. If it is, then how to configure the piston for
json out put?

I am using Django 1.1.1 and Django-Piston0.2.2

handler.py
class MyHandler(BaseHandler):

allowed_methods = ('GET',)
fields = ('fields',...
)


model = myModel

def read(self, name=None):
return self.model.objects.all()



urls.py
urlpatterns = patterns('',
(r'^url$',my_Resource, { 'emitter_format': 'json' }),
}

Many thanks for the help.

Wayne

--
You received this message because you are subscribed to the Google Groups "django-piston" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-pisto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-piston?hl=en.

Reply all
Reply to author
Forward
0 new messages