On 15 September 2010 16:17, nigeke...@googlemail.com <nigeke...@googlemail.com> wrote: > Thanks for response Richard. Not sure exactly what you mean. > > The response from the server when I key in the url directly to chrome > is a json array/hash of previously entered data: > > [{"post": > {"device":"palm","location":"dublin","created_at":"2010-09-09T06:03:58Z","updated_at":"2010-09-09T06:03:58Z","nickname":"nige","level": > 82,"id":1,"devid":"001000230","score":200,"message":"my score sucks"}}, > {"post": > {"device":"iphone","location":"london","created_at":"2010-09-09T17:13:20Z","updated_at":"2010-09-09T17:13:20Z","nickname":"greg","level": > 54,"id":2,"devid":"465465468","score":6000,"message":"Check it out. > Love this game!!"}}} > > Matches what I entered. So that's ok. > > The server is a Rails server. Webrick outputs the following when I use > the code from my first post: > > Processing ApplicationController#index (for y.y.y.221 at 2010-09-15 > 14:59:22) [OPTIONS] > > But by directly keying in the url to chrome Rails responds with: > > Processing PostsController#index to js (for y.y.y.221 at 2010-09-15 > 15:01:16) [GET] > > It's like the request is not understood by Rails.Or it is malformed > somehow. It doesn't get it's a GET request and bypasses the > PostsController. > > > > > On Sep 15, 2:21 pm, Richard Quadling <rquadl...@gmail.com> wrote: >> On 15 September 2010 12:28, nigeke...@googlemail.com >> >> >> >> >> >> <nigeke...@googlemail.com> wrote: >> > I have the following request in my app. It works fine in Safari 5. >> >> > new Ajax.Request('http://x.x.x.x:3000/posts.js', >> > { >> > method:'get', >> > requestHeaders: {Accept: 'application/json'}, >> > onSuccess: function(transport){ >> > var response = transport.responseText; >> > var posts = response.evalJSON(); >> > etc.... >> > } >> > }); >> >> > In chrome 5 I get the error Refused to get unsafe header "X-JSON". >> >> > When I point the chrome browser at my url json is returned but with >> > the warning: >> > Resource interpreted as document but transferred with MIME type text/ >> > javascript. >> >> > The content type in the request is application/x-www-form-urlencoded. >> >> > Any ideas? >> >> > Nige >> >> What type is the response forhttp://x.x.x.x:3000/posts.js
But what are the HTTP headers? In PHP ... // Send X-JSON / application/json headers and content if possible. if (!headers_sent()) { if (False !== $a_JSON['Header']) { $a_JSON['Header']['Queries'] = $a_Query; $a_JSON['Header']['Session'] = $_SESSION; header('X-JSON: ' . json_encode($a_JSON['Header'])); } if (False !== $a_JSON['Detail']) { header('Content-type: application/json'); sort($a_JSON['Detail']); echo json_encode($a_JSON['Detail']); } } >From that, in JavaScript, I can use ... response.headerJSON and response.responseJSON Without the headers, things don't work properly as the browser assumes it is text or html coming down the line. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.