Running your own AJAX from your HP

Running your own AJAX from your HP

Just a technical note I wanted to add. Sometimes it’s desirable to have your own server scripts that you call from a browser AJAX request. Languages like PHP and C# have lots of goodies you can use, especially to create their own HTTP client to make a request, and to return an AJAX response in a sane, efficient way.  When you start getting into the machine behind IMVU, you’ll see things aren’t always so pretty.

But if you try it, you’ll probably get an “access denied” error in the debugger, and things just don’t show up in the browser the way they should.  I recently learned there is a host header you should add to your response that circumvents this untidiness.

Access-Control-Allow-Origin: *

If you’re using C#, perhaps using a generic ASHX handler, you can add the following codes to the ProcessRequest method:

context.Response.AddHeader("Access-Control-Allow-Origin", "*");

PHP is even easier:

<?php header("Access-Control-Allow-Origin: *"); ?>

Maybe this is useful to you, because it allowed my codes to run. Caveat emptor, as usual.