title: Problems with obtaining Wikipedia token
body: <p>I am trying to obtain Wikipedia edit token using this code:</p>
  
  <pre><code>$.getJSON("https://en.wikipedia.org/w/api.php?action=query&amp;meta=tokens&amp;format=json&amp;callback=?", function (data) {
      console.log( data );
  });
  </code></pre>
  
  <p>However, I am receiving this error:</p>
  
  <blockquote>
    <p>"Tokens may not be obtained when the same-origin policy is not applied."</p>
  </blockquote>
  
  <p>What is the correct way to get the token using jQuery?</p>
  
  <p><strong>EDIT:</strong> I have tried following approaches (based on comments):</p>
  
  <ul>
  <li>Removing callback=? and adding origin=* - that throws the original token error</li>
  <li><p>Using modified example from <a href="https://www.mediawiki.org/wiki/Manual:CORS" rel="nofollow noreferrer">here</a>:</p>
  
  <pre><code>$.ajax( {
   url: 'https://en.wikipedia.org/w/api.php',
   data: {
    action: 'query',
    meta: 'tokens',
    format: 'json',
    origin: 'http://example.com'
   },
   xhrFields: {
    withCredentials: true
   },
   dataType: 'json'
  }).done( function ( data ) {
   console.log(data);
  });
  </code></pre>
  
  <p>This returns the Cross-Origin error mentioned in comments.</p></li>
  </ul>