Can't get things to work. #1

Closed
jeroenooms opened this Issue Jul 14, 2012 · 16 comments

Projects

None yet

5 participants

@MoonScript
Owner

I updated the README with more info and a link to a working jsFiddle example:
https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/blob/master/README

@jeroenooms

Thanks! Is there any way you can show an example that uses POST and
also the error handler in case the post returns something else than
200?

On Fri, Jul 20, 2012 at 1:41 AM, Jason Moon
reply@reply.github.com
wrote:

I updated the README with more info and a link to a working jsFiddle example:
https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/blob/master/README


Reply to this email directly or view it on GitHub:
#1 (comment)

@MoonScript
Owner

I updated the jsFiddle to show both a GET and a POST that returns both XML and JSON:
http://jsfiddle.net/MoonScript/Q7bVG/

That should be enough to illustrate how this works. You should be able to do some testing against your own service that would return a 500 status.

@grEvenX
grEvenX commented Oct 11, 2012

Basicly this implementation should be fixed or just wiped off the earth. There's too many posts referring to this implementation as a "solution" for jQuery IE cross-domain ajax-requests right now, and all will have problems with it as long as they are sending data.
I will recommend people to look at this implementation instead: https://github.com/jaubourg/ajaxHooks/blob/master/src/xdr.js

@MoonScript
Owner

I don't appreciate the tone of your email.

What needs fixing? I have links to jsFiddle with working examples. I'd be happy to fix this if you just tell me what's not working.

-Jason Moon

On Oct 11, 2012, at 4:52 AM, Even André Fiskvik notifications@github.com wrote:

Basicly this implementation should be fixed or just wiped off the earth. There's too many posts referring to this implementation as a "solution" for jQuery IE cross-domain ajax-requests right now, and all will have problems with it as long as they are sending data.
I will recommend people to look at this implementation instead: https://github.com/jaubourg/ajaxHooks/blob/master/src/xdr.js


Reply to this email directly or view it on GitHub.

@grEvenX
grEvenX commented Oct 11, 2012

lol, I'm sorry. I do understand I sounded very harsh, this is what two-three days of debugging CORS related issues in IE can give you. If you look at this github project's "issues" list you'll find the basic issue with this implementation, and that is that it doesn't post any data at all...

@MoonScript
Owner

I'm going to update this now so that it will POST any data that was supplied.

@MoonScript MoonScript closed this Oct 11, 2012
@jeroenooms

Honestly I have never gotten this to work either:

http://www.stat.ucla.edu/~jeroen/cors/test1.html

I am not sure XDR supports POST arguments at all. And it also doesn't seem to be able to read a response text and status code if the return was anything else than 200 (and did include the cors header)

@MoonScript
Owner

@jeroenooms I think I found out what the problem is.

  1. Make sure to specify the dataType option in the jQuery ajax call. I don't think the ajaxTransport code will pick it up unless the dataType is explicitly set.
  2. When you do a POST with an XDR, you cannot control the Content-Type of the request - it's always set as "text/plain". So I believe the server that you are posting to is throwing an error when it encounters a request with that Content-Type. You can verify that by tweaking your test code to manually set the jQuery ajax contentType to "text/plain" and you'll see that you'll get an error in modern browsers as well.
@MoonScript
Owner

@jeroenooms More info in item number 4 on this page about posting as text/plain.

@grEvenX I believe all issues have been addressed. This jQuery extension should be working properly, now.

@jeroenooms

Thanks for pointing this out. The MSDN page says:

"To workaround this issue, server code that currently processes HTML
Forms must be rewritten to manually parse the request body into
name-value pairs when receiving requests from XDomainRequest objects.
This makes adding support for the XDomainRequest object more difficult
than it would be otherwise."

Now this is really not a solution in my opinion. If I was in the
position to rewrite server code, I might as well just use one of the
other hacks and work-arounds like jsonp or easyxdm. It completely
defeats the purpose of using CORS in the first place. The entire
purpose of using your plugin would be to make existing jquery clients
that use cors compatible with IE, and, as I understand now, that is
simply not possible.

Thanks again for your support and your efforts on this plugin; but I
am afraid microsoft has wasted all of our time :-(

On Thu, Oct 11, 2012 at 12:52 PM, Jason Moon notifications@github.com wrote:

@jeroenooms More info in item number 4 on this page about posting as text/plain.

@grEvenX I believe all issues have been addressed. This jQuery extension should be working properly, now.


Reply to this email directly or view it on GitHub.

@MoonScript
Owner

I agree, except that if you're doing GET requests, then it will work fine.

@mab1777
mab1777 commented Feb 18, 2013

Great job. Do you have a solution for cases where we do not use jQuery?

Thanks!!

@MoonScript
Owner

No, this is a jQuery extension. But, you could probably see how to do it by looking at the code. I only use jQuery so I don't have a need for a non-library solution right now.

On Feb 18, 2013, at 4:41 PM, mab1777 notifications@github.com wrote:

Great job. Do you have a solution for cases where we do not use jQuery?

Thanks!!


Reply to this email directly or view it on GitHub.

@ronnyfm
ronnyfm commented May 1, 2013

Any requirements from the side of the server which the data is retrieved? I am trying a GET request, dataType is specified, but I get the same error of "Access Denied". Thank you!

Look at this:

Access-Control-Allow-Head... Content-Type
Access-Control-Allow-Meth... GET, POST, PUT, DELETE, OPTIONS
Content-Length 1053
Content-Type application/xml; charset=utf-8
Date Wed, 01 May 2013 22:56:20 GMT
Server Microsoft-IIS/7.5
X-Powered-By ASP.NET
access-control-allow-orig... *

@MoonScript
Owner

The best way to get help and debug issues like this is to create a jsFiddle with your sample code. Of course that means your server (on the other domain) that contains the AJAX data must be on the public internet.

It might not matter, but you should probably properly camel-case your response header:
Access-Control-Allow-Origin: *

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment