Working with AJAX calls to external resources

Hey all!

I'm checking a number of sources to see if someone can help me. I've got a ticket request in for Knack and for itDuzzit. I'll probably try StackExchange as well.

I'm attempting an AJAX call out of a Knack App. I'm pointing the call to a URL in itDuzzit which should receive the json request.

After doing a lot of testing I've boiled my issue down to this: the AJAX call won't let me set Content-Type to application/json because when I do, my browser (Chrome) first sends an "OPTIONS" request, and apparently doesn't receive the "Content-Type" affirmative response.

Here's my troubleshooting:

When I do a normal call (no custom content-type headers etc), the duzzit fires, except it doesn't receive the data (presumably because it's x-www-form-encoded).

I ran a test using a RESTful chrome add-on, which allows me to try various API calls. I used the same raw data, same URL, only set the content-type to application/json, and it fired no problem (and passed the data through!).

I then switched it to application/x-www-form-encoded... it fired, but didn't receive any data.


The only thing I can find here is that the original AJAX call needed to be encoded for application/json, but whenever I attempt to do that with custom headers or contentType, the browser automatically fires an OPTIONS calls, looking for the allowed headers. When itDuzzit only responds with the accepted METHODS and no accepted Headers, the browser doesn't fire the actual POST with the data.

Any thoughts on solution here? I've been banging my head against this issue for hours.

My thought is that perhaps I can tell the server/browser to send anyway? Or something long those lines?

I know this isn't quite a KnackHQ issue, and I've put a support request in to itDuzzit, but perhaps there is a work-around?



High-five! I solved it!

I learned that pre-flight is triggered by application/json content type.

I changed to text/plain and just stringified the JSON, and it works like a charm.

Congratulations everyone! :-)