Problem with Ajax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with Ajax

Ankh'nAton
Hi,
I try some asynchronous data fetching using the Picasa API. The
response from Picasa is an atom feed, of which I'd like to pick the
images' urls. So I founded a new class "PicasaQuery", where instances
can be configured to a certain query of images and then fetch the
search result from the Picasa website. Therefor I have a method
"execute", which constructs the request url and does the query. The
query's response is kept in the instance variable "responseXML".

  Object subclass: #PicasaQuery
        class instanceVariableNames: 'baseURL'

        instanceVariableNames: 'query maxResults responseXML'
        package: 'TB-PicasaAPI'


  execute
        "tb: If maxResult is set, then execute the query and answer
        the response markup or an empty string."
        | uri |
        responseXML := ''.
        maxResults notNil ifTrue: [
                uri := (self class baseURL),'q=',query,'&max-results=',maxResults.
                jQuery ajax: uri options: #{
                        'accept' -> 'application/xml'.
                        'success'  -> [ :data :txtStatus :xhr | responseXML := data ].
                        'error' -> [window alert: 'Request failed at:  ', uri]
                }
        ].
        ^responseXML


My test query goes like...

  response :=  PicasaQuery new
        query: 'Frank+Zappa';
        maxResults: 10;
        execute.

...where execute returns the response or an empty string. The uri in
this method works fantastic in any web browser, but all that I get
here, is that error alert.

Any suggestions?

Regards...
Reply | Threaded
Open this post in threaded view
|

Re: Problem with Ajax

Pablo Iaria
Hola,

You should handle correctly the acync callback. For example by changing the ajax callback to invoke a #responseXML: method:

 execute
       "tb: If maxResult is set, then execute the query and answer
       the response markup or an empty string."
       | uri |
       maxResults notNil ifTrue: [
               uri := (self class baseURL),'q=',query,'&max-results=',maxResults.
               jQuery ajax: uri        options: #{
                       'accept' -> 'application/xml'.
                       'success'  -> [ :data :txtStatus :xhr | self responseXML: data ].
                       'error' -> [window alert: 'Request failed at:  ', uri]
               }
       ].

Saludos!
Pablo.-


On Thu, Mar 1, 2012 at 5:06 PM, Tom <[hidden email]> wrote:
Hi,
I try some asynchronous data fetching using the Picasa API. The
response from Picasa is an atom feed, of which I'd like to pick the
images' urls. So I founded a new class "PicasaQuery", where instances
can be configured to a certain query of images and then fetch the
search result from the Picasa website. Therefor I have a method
"execute", which constructs the request url and does the query. The
query's response is kept in the instance variable "responseXML".

 Object subclass: #PicasaQuery
       class instanceVariableNames: 'baseURL'

       instanceVariableNames: 'query maxResults responseXML'
       package: 'TB-PicasaAPI'


 execute
       "tb: If maxResult is set, then execute the query and answer
       the response markup or an empty string."
       | uri |
       responseXML := ''.
       maxResults notNil ifTrue: [
               uri := (self class baseURL),'q=',query,'&max-results=',maxResults.
               jQuery ajax: uri        options: #{
                       'accept' -> 'application/xml'.
                       'success'  -> [ :data :txtStatus :xhr | responseXML := data ].
                       'error' -> [window alert: 'Request failed at:  ', uri]
               }
       ].
       ^responseXML


My test query goes like...

 response :=  PicasaQuery new
       query: 'Frank+Zappa';
       maxResults: 10;
       execute.

...where execute returns the response or an empty string. The uri in
this method works fantastic in any web browser, but all that I get
here, is that error alert.

Any suggestions?

Regards...

Reply | Threaded
Open this post in threaded view
|

Re: Problem with Ajax

Ankh'nAton
Hi and thank You!

I understand Your objection, but pitty it does not solve the problem.
I have tried different 'accept' types like 'application/xhtml+html'
and 'application/atom+xml', but with no success either.

Cheers...

On 1 Mrz., 21:50, Pablo Iaria <[hidden email]> wrote:

> Hola,
>
> You should handle correctly the acync callback. For example by changing the
> ajax callback to invoke a #responseXML: method:
>
>  execute
>        "tb: If maxResult is set, then execute the query and answer
>        the response markup or an empty string."
>        | uri |
>        maxResults notNil ifTrue: [
>                uri := (self class
> baseURL),'q=',query,'&max-results=',maxResults.
>                jQuery ajax: uri        options: #{
>                        'accept' -> 'application/xml'.
>                        'success'  -> [ :data :txtStatus :xhr | self
> responseXML: data ].
>                        'error' -> [window alert: 'Request failed at:  ',
> uri]
>                }
>        ].
>
> Saludos!
> Pablo.-
>
>
>
>
>
>
>
> On Thu, Mar 1, 2012 at 5:06 PM, Tom <[hidden email]> wrote:
> > Hi,
> > I try some asynchronous data fetching using the Picasa API. The
> > response from Picasa is an atom feed, of which I'd like to pick the
> > images' urls. So I founded a new class "PicasaQuery", where instances
> > can be configured to a certain query of images and then fetch the
> > search result from the Picasa website. Therefor I have a method
> > "execute", which constructs the request url and does the query. The
> > query's response is kept in the instance variable "responseXML".
>
> >  Object subclass: #PicasaQuery
> >        class instanceVariableNames: 'baseURL'
>
> >        instanceVariableNames: 'query maxResults responseXML'
> >        package: 'TB-PicasaAPI'
>
> >  execute
> >        "tb: If maxResult is set, then execute the query and answer
> >        the response markup or an empty string."
> >        | uri |
> >        responseXML := ''.
> >        maxResults notNil ifTrue: [
> >                uri := (self class
> > baseURL),'q=',query,'&max-results=',maxResults.
> >                jQuery ajax: uri        options: #{
> >                        'accept' -> 'application/xml'.
> >                        'success'  -> [ :data :txtStatus :xhr | responseXML
> > := data ].
> >                        'error' -> [window alert: 'Request failed at:  ',
> > uri]
> >                }
> >        ].
> >        ^responseXML
>
> > My test query goes like...
>
> >  response :=  PicasaQuery new
> >        query: 'Frank+Zappa';
> >        maxResults: 10;
> >        execute.
>
> > ...where execute returns the response or an empty string. The uri in
> > this method works fantastic in any web browser, but all that I get
> > here, is that error alert.
>
> > Any suggestions?
>
> > Regards...
Reply | Threaded
Open this post in threaded view
|

Re: Problem with Ajax

Ankh'nAton
Hm... Using firebug reveals a respose header with status="200 ok" but
the response XML is empty :(

Cheers...

On 1 Mrz., 22:44, Tom <[hidden email]> wrote:

> Hi and thank You!
>
> I understand Your objection, but pitty it does not solve the problem.
> I have tried different 'accept' types like 'application/xhtml+html'
> and 'application/atom+xml', but with no success either.
>
> Cheers...
>
> On 1 Mrz., 21:50, Pablo Iaria <[hidden email]> wrote:
>
>
>
>
>
>
>
> > Hola,
>
> > You should handle correctly the acync callback. For example by changing the
> > ajax callback to invoke a #responseXML: method:
>
> >  execute
> >        "tb: If maxResult is set, then execute the query and answer
> >        the response markup or an empty string."
> >        | uri |
> >        maxResults notNil ifTrue: [
> >                uri := (self class
> > baseURL),'q=',query,'&max-results=',maxResults.
> >                jQuery ajax: uri        options: #{
> >                        'accept' -> 'application/xml'.
> >                        'success'  -> [ :data :txtStatus :xhr | self
> > responseXML: data ].
> >                        'error' -> [window alert: 'Request failed at:  ',
> > uri]
> >                }
> >        ].
>
> > Saludos!
> > Pablo.-
>
> > On Thu, Mar 1, 2012 at 5:06 PM, Tom <[hidden email]> wrote:
> > > Hi,
> > > I try some asynchronous data fetching using the Picasa API. The
> > > response from Picasa is an atom feed, of which I'd like to pick the
> > > images' urls. So I founded a new class "PicasaQuery", where instances
> > > can be configured to a certain query of images and then fetch the
> > > search result from the Picasa website. Therefor I have a method
> > > "execute", which constructs the request url and does the query. The
> > > query's response is kept in the instance variable "responseXML".
>
> > >  Object subclass: #PicasaQuery
> > >        class instanceVariableNames: 'baseURL'
>
> > >        instanceVariableNames: 'query maxResults responseXML'
> > >        package: 'TB-PicasaAPI'
>
> > >  execute
> > >        "tb: If maxResult is set, then execute the query and answer
> > >        the response markup or an empty string."
> > >        | uri |
> > >        responseXML := ''.
> > >        maxResults notNil ifTrue: [
> > >                uri := (self class
> > > baseURL),'q=',query,'&max-results=',maxResults.
> > >                jQuery ajax: uri        options: #{
> > >                        'accept' -> 'application/xml'.
> > >                        'success'  -> [ :data :txtStatus :xhr | responseXML
> > > := data ].
> > >                        'error' -> [window alert: 'Request failed at:  ',
> > > uri]
> > >                }
> > >        ].
> > >        ^responseXML
>
> > > My test query goes like...
>
> > >  response :=  PicasaQuery new
> > >        query: 'Frank+Zappa';
> > >        maxResults: 10;
> > >        execute.
>
> > > ...where execute returns the response or an empty string. The uri in
> > > this method works fantastic in any web browser, but all that I get
> > > here, is that error alert.
>
> > > Any suggestions?
>
> > > Regards...