Cross domain ajax in a multisite setup I have a drupal multisite install so that two sites can share the same codebase. In a custom module that both sites use, the ajax works on one site but with the other site it returns the error status 200. What my module does is that it creates a new "article" node programmatically. 

I read somewhere that this is a crossdomain ajax problem, even though both sites are really on the same hard drive of the same server.

The views module, which also uses ajax, works on both sites with no problem. 

How can I make the ajax work? I'll give up the multisite way if it creates more problems than it solves

Update: here is the jquery code :

(function ($) {
    Drupal.behaviors.addArticle = {
        attach: function (context, settings) {                              
            var addstuffAjaxLink = $(".addsomething");          
            addstuffAjaxLink.click(function(e) {                            
                var ajaxpath = 'addstuff/ajax';         
                $.ajax({
                    type: "POST",
                    url: ajaxpath,
                    data: {'from_js': true},
                    dataType: "json",
                    success: function (data) {              
                        if (data.message) {                             
                            var message= data.message;                      
                            alert(message);                             
                        }
                    },
                    error: function (xmlhttp) {
                        alert('An error occured: ' + xmlhttp.status);                       
                    }
                });         
            });
        }
    };
})(jQuery);


and this is the custom module php code:

&lt;?php
/**
 * Implements hook_menu().
 */
function addstuff_menu() {
  $items = array();

  $items['addstuff/ajax'] = array(
   'title' =&gt; 'Add Stuff',
    'page callback' =&gt; 'addstuff_callback',
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}
/**
 * Menu callback.
 */
function addstuff_callback() {
    if ($_POST['from_js']) {
        global $user;

        $newnode = new stdClass();
        $newnode-&gt;uid = $user-&gt;uid;
        $newnode-&gt;name = $user-&gt;name;   
        $newnode-&gt;language = LANGUAGE_NONE;
        $lan=$newnode-&gt;language;
        $newnode-&gt;status = 1;     
        $newnode-&gt;promote = 0;
        $newnode-&gt;sticky = 0;
        $newnode-&gt;created = timestamp;                      
        $newnode-&gt;title = 'New Article';
        $newnode-&gt;type = 'article';

        $newnode-&gt;field_body = array(
            $lan =&gt; array(
                array(
                    'value' =&gt; 'Click HERE to add some text.',
                    'format'=&gt; 'full_html',
                    'safe_value' =&gt; 'Click HERE to add some text.',
                )
            )
        );
        node_save($newnode);            
        $response = array(
            'message' =&gt; 'Article Created',
        );
        return drupal_json_output($response);
        exit;           
    } else {
        $response = array(
            'message' =&gt; 'There was an error',
        );
        drupal_json_output($response);
        exit;
    }
}
/**
 * Implements hook_init().
 */
function addstuff_init() {
  drupal_add_js(drupal_get_path('module', 'addstuff') . '/addstuff.js');
}
The first thing I'd probably do is to change the url option of $.ajax to something like:

$.ajax({
  // your code goes here
  url: Drupal.settings.basePath + 'addstuff/ajax',
  // more of your code goes here
});


So, what could be happening (assuming of course, that you have clean URLs enabled on both sites) is that when you are on a page on your site with the Drupal path, say, node/add and click on your link, the AJAX request to addstuff/ajax without the leading slash (base path) goes to node/addaddstuff/ajax which will return HTML and not JSON as expected. Hence, jQuery throws a parseerror and Drupal calls its error handler. You can check this by inspecting the XHR requests being sent out from the Network tab of your browser's developer console.

However, this doesn't explain how your code works as expected on one site but not the other.