0

I have a jQuery: $('#gather-facts').html('<script type="text/javascript">function gatherFacts() { var r = new XMLHttpRequest(); r.open("GET", "https://<server>/apps/merge?host=" + (document.title).slice(18,-9), false); r.send(); }; window.onload = gatherFacts;</script>');'); in my MediaWiki:Common.js which is working fine except for that I need to run the script in synchronous mode.

There is a async option for jQuery but I can't seem to figure out how to add it to the above.

Currently using MediaWiki 1.25.2

Corex Cain
  • 123
  • 1
  • 7
  • I think you need to have a look at this link: [What is the X/Y problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – mplungjan Jan 15 '16 at 08:21
  • NOW you added the missing information!!! so you ARE executing AJAX. Please show exactly what a bunch of stuff is doing so we can help you. I am very close to closing this question as a duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – mplungjan Jan 15 '16 at 08:35
  • So true, updated the question – Corex Cain Jan 15 '16 at 08:40

1 Answers1

0

Ok so the code is

$('#gather-facts').html('<script type="text/javascript">function gatherFacts() { var r = new XMLHttpRequest(); r.open("GET", "https://<server>/apps/merge?host=" + (document.title).slice(18,-9), false); r.send(); }; window.onload = gatherFacts;</script>');');`

Assuming the origin is the same as the page you are on, you want this instead

$(function() {
  $('#gather-facts').load("/apps/merge?host=" + 
    document.title.slice(18,-9));
});
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • It's in HTML, meaning: , I've updated my question, sorry for the confusion. – Corex Cain Jan 15 '16 at 08:13
  • Yeah, but that would still make jquery run in async – Corex Cain Jan 15 '16 at 08:17
  • There is nothing synchronous or asynchronous about your question so far. If you have `.load()`, `.get()` or `$.ajax()` then you may have some async/sync issues, but so far you have shown no such code – mplungjan Jan 15 '16 at 08:19
  • Is `function stuff() { return "a bunch of stuff"; } $("#id").html(stuff());` what is called a callback? – Corex Cain Jan 15 '16 at 08:31
  • No. Not at all. It is a function that returns stuff. A callback is something you execute after an async call which I still think you are confused about – mplungjan Jan 15 '16 at 08:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100743/discussion-between-corex-cain-and-mplungjan). – Corex Cain Jan 15 '16 at 08:33