Thanks a lot Sean, that works for me. One last question. I've been reading about this for the past 4 hours and I still don't understand why the browser doesn't get pass the preflight request when I do a normal request, is something the other side must sent to accept the connection?
On Nov 8, 7:19 pm, Sean McArthur <[email protected]> wrote: > Yes, the server would have to wrap it. If you have no control, you could > consider using YQL. YQL could let you provide the XML location, and even get > it converted to JSON. You can play with it in the console here, and after > making sure you get what you want, copy the url it provides > > http://developer.yahoo.com/yql/console/#h=select%20*%20from%20xml%20w... > > On Mon, Nov 8, 2010 at 10:17 AM, Nacho G <[email protected]> wrote: > > I think I understand. It is the server which has to wrap the response > > in the callback function I send. But that must be implemented on the > > other side, isn't it ? > > > On Nov 8, 7:14 pm, Nacho G <[email protected]> wrote: > > > I don't have control and I have to figure this out without asking the > > > engineers who has put the file. I'm trying to get the data from an > > urlhttp://www.url.com/path/filename.xml. How can I now if I have access > > > to passing a callback get parameter? > > > I'm trying something like this: > > > > var request = new Request.JSONP({ > > > url: 'http://www.url.com/path/filename.xml', > > > method : 'GET', > > > callbackKey: 'callback=myfunc' > > > }); > > > request.send (); > > > > window.myfunc = function(data) { > > > > }; > > > > myfunc is supposed to do something, I don't know what. > > > > On Nov 8, 7:03 pm, Sean McArthur <[email protected]> wrote: > > > > > Do you have control over the XML resource? I assume it's coming from > > some > > > > back-end script that is generating it. If not, you could ask the > > engineers > > > > that do you have access to allow passing a "callback" GET parameter. > > > > > On Mon, Nov 8, 2010 at 9:59 AM, Nacho G <[email protected]> wrote: > > > > > Excuse my ignorance but I'm not sure how to do that and I can't find > > > > > more information about the jsonp callback > > > > > Could you give a little example ? > > > > > > thanks a lot > > > > > > On Nov 8, 6:31 pm, Sean McArthur <[email protected]> wrote: > > > > > > You could look up the new cross domain request stuff, but using > > JSONP > > > > > might > > > > > > be easier. It's not parsing the XML as JSON. > > > > > > > The idea of JSONP is that you make a cross domain request, and > > provide a > > > > > > callback function. The server spits out JSON, and wraps it in the > > > > > callback > > > > > > function. > > > > > > > my_callback({ "a":"stuff", "b":"otherstuff"}); > > > > > > > Request.JSONP makes the callback stuff real easy for you. As well, > > this > > > > > > request is put inside a script element, so it can execute as > > JavaScript. > > > > > To > > > > > > get your XML request to work, it would have to wrap the XML with > > the > > > > > > callback method that Request.JSONP is sending, and escape all the > > XML to > > > > > fit > > > > > > inside a single string. > > > > > > > my_callback('<things><thing id="one">a thing</thing><thing > > id="two">it\'s > > > > > > another thing</thing></things>'); > > > > > > > On Mon, Nov 8, 2010 at 8:43 AM, Nacho G <[email protected]> wrote: > > > > > > > Hello, I'm trying to get data from a remote XML file but I'm > > getting a > > > > > > > preflight request with REQUEST because I'm requesting a > > cross-domain > > > > > > > XMLHttpRequest. > > > > > > > > With Request.JSONP I don't have that problem and I get the data > > from > > > > > > > the remote XML but the problem is that mootools parse the result > > and > > > > > > > it gives an error as the result is XML not JSON. > > > > > > > > how can I make a regular Request avoiding the preflight request? > > or > > > > > > > how can I stop JSONP from parsing the result? > > > > > > > > thanks
