Hi Shawn, Thanks for your help. So, you're right I do want to do asynchronous. This was a mistake on my part.
I actually do need to see the parameters in the webserver log file, so I need to do a GET. By using GET, and the 'data' key with my data, it appears it throws in a random number in their by default so the browser won't cache. However, still getting it coming across as a OPTIONS request, very strange. So all this is doing is sending a 'pixel' to my stats webserver. index.gif is a 0 byte file, and there is nothing returned. I don't need to do anyting on the browser end to process any result. All I care about is that I have my data in my log file so I can process and aggregate later. About the crossdomain problem, I do not really know too much about this. All I know is that the main request and the stat pixel are both coming from/to 2 different subdomains: a.myserver.com and stats.myserver.com. They are both coming across fine and the stats are appearing in my logs. I guess the only problem/issue/weirdness is that I don't know why it comes across as OPTIONS at this point. Thanks for your help....greatly appreciate it. Ryan On Sat, Oct 24, 2009 at 2:02 AM, Shawn <sgro...@open2space.com> wrote: > > Your URL is the culprit. And the way you are passing data. > > Doing http://myserver.com/index.gif?id=1&event=e is a GET request - the > params are on URl directly. If you want this data to appear in the POST > then you need to pass them right: > > > $.ajax({ > async: false, > type: 'POST', > url: 'myserver.com/index.gif', > data: 'id=1&event=e', > cache: false, > timeout: 0 > }); > > This *should* take care of the OPTIONS thing (I don't know anymore details > on that at the moment..) > > Some observations. Did you really mean to do a synchronous call? > Synchronous calls are "blocking" - they stop further processing until a > result is returned. If that result never returns, you've hung your code. > This is what the timeout attempts to handle. There IS a time and place for > synchronous calls, but with what you've given us so far I don't think this > is one of them. To make it asynchronous (which is what the first A in Ajax > means), you'd change your code like this: > > $.ajax({ > type: 'POST', > url: 'myserver.com/index.gif', > data: 'id=1&event=e', > cache: false, > }); > > Next, you are setting cache to false - I'm assuming because you really want > the server to process each request. What I've done in the past is to just > attach a random number to the URL. > > url: 'myserver.com/index.gif?r=' + Math.random() > > this works well enough for my needs, though I'm not sure if this is a "best > practice". > > Next, your url parameter points to 'myserver.com/index.gif'. $.ajax > cannot do cross domain requests (unless you use jsonp, which is a little > beyond this discussion...). The URL should be a relative path to a file > from your current page. Also, why are you requesting index.gif? Do you > have serverside configs that redirect index.gif? Why not just call > "mypage.php" instead? Remember that an Ajax call is a REQUEST of a > resource, and that resource can return whatever. I suspect you are > converting some old school code where the request for a gif file was a > precursor to modern Ajax, but could be wrong. > > Finally, Your request will return a response of some type. You should be > handling that response in the success and/or error properties. Then again, > they are not required. But what happens if something unexpected happens? > Does your app fail gracefully? > > This should get you pointed in the right direction. I suspect you may have > problems with your event parameter (it appears it should be an object, not > the letter 'e'...), but that is relatively minor. > > Hope this helps. > > Shawn > > Ryan White wrote: > >> Hey All, >> So I am having a weird situation when using the $.ajax method. And have a >> couple questions regarding this. What I am doing is basically just using >> this AJAX call to send a 'pixel' back to my server so I can collect stats on >> events. This event fires once every 30 seconds. >> >> $.ajax({ >> async: false, >> type: 'POST', >> url: myserver.com/index.gif?id=1&event=e < >> http://myserver.com/index.gif?id=1&event=e> >> >> cache: false, >> timeout: 0 >> }); >> >> My requests keep coming in as OPTIONS call, instead of POST. Every once >> in a while I will get a random rogue GET request that basically mimics the >> previous OPTIONS request. The OPTIONS come very 30 seconds. The rogue GET >> comes whenever, only seldomly. >> >> 1) What is OPTIONS and why would it come out as OPTIONS instead of POST? >> 2) Why would GET requests come at all? Why would they come randomly >> (seemingly) without being called? >> 3) Is this a proper way of sending a 'pixel' back to my server to track >> stats? If not, what is a better way? >> >> Very new to AJAX, and definitely don't know all the internals. Any help >> would be greatly appreciated. >> >> Thanks in advance.... >> >