title: Get total list items from Sharepoint on another domain using SPServices
body: <p>this is my first post in Stackoverflow. Hope you guys can help me with my problem. I have a HTML page on domain1.sharepoint.com and I'm trying to get the total list items from a SharePoint on domain2.sharepoint.com using JQuery+SPServices.</p>
  
  <p>I understand that due to same-origin policy, I need to use XMLHttpRequest (CORS) to get the data I need. Unfortunately, I'm not sure how to put the XMLHttpRequest into SPServices. I've tried, and getting 'undefined' error. I'm pretty new with JavaScript, appreciate all the help.</p>
  
  <p>Here's what I've done so far:</p>
  
  <pre><code>$.support.cors = true;
  function createCORSRequest(method, refURL) {
    var xhr = new XMLHttpRequest();
    if ("withCredentials" in xhr) {
      xhr.open(method, refURL, true);
    } else if (typeof XDomainRequest != "undefined") {
      xhr = new XDomainRequest();
      xhr.open(method, refURL);
    } else {
      xhr = null;
    }
    return xhr;
  }
  
  function makeCorsRequest() {
    var refURL = 'http://domain1.sharepoint.com';
    var spURL = refURL;
  
    var xhr = createCORSRequest('GET', spURL);
    if (!xhr) {
      alert('CORS not supported');
      return;
    }
    xhr.onload = function() {
      $().SPServices({
          operation: "GetListItems",
          webURL: spURL,
          listName: "Message Log",
          viewName: "{70DFBF9A-5266-4D69-AD01-E848301B51BB}",
          async: false,
          CAMLViewFields: "&lt;ViewFields&gt;&lt;FieldRef Name='Status' /&gt;&lt;/ViewFields&gt;",
          completefunc: function (xData, status) {
              $("#countlist").html($(xData.responseXML).find("z\\:row").length);
          }
      });
  };
  
    xhr.onerror = function(e, jqxhr) {
      alert('Woops, there was an error making the request. ' + jqxhr);
    };
  
    xhr.send();
  }
  
  onload = makeCorsRequest;
  </code></pre>