Note that there are some explanatory texts on larger screens.

plurals
  1. POError using ajax to send JSON data to a private server
    primarykey
    data
    text
    <p>I am pretty new to writing userscripts for Chrome/Firefox. I was trying to get the AJAX generated JSON data from a website and send them to my own server, to analyze them and put them into a database.</p> <p>I managed to send the data with Ajax and put them into a text file on my own server. But in the Chrome Console it says that I have:</p> <blockquote> <p>Uncaught SyntaxError: Unexpected token j</p> </blockquote> <p>, but I already have got each message, that <em>'Data were sent'</em> and that I'm <em>'After the call'</em> -those are the logging messages.</p> <p>Is there a callback, that I should implement, or am I missing something obvious? I am putting a shortened version of my code up here.</p> <pre><code>// Injecting javascript in the original page function inject(func) { var source = func.toString(); var script = document.createElement('script'); script.innerHTML = "(" + source + ")()"; document.body.appendChild(script); } function injection() { } // This function intercepts the ajax function interceptAjax() { $('body').ajaxSuccess ( function (event, requestData, settings) { serverData = requestData.responseText; if(JSON.parse(settings.data).method == "dashboard.getPaginatedPlextsV2"){ console.log("Sending"); $.ajax({ type: "POST", url: "http://mywebsite.com/collectdata.php", data: { json: JSON.stringify(serverData) }, success: function(msg) { console.log("Data were sent"); }, error: function(xhr, ajaxOptions, thrownError) { console.log("Failed: " + xhr.status + " - " + thrownError); } }); console.log("After the call"); } } ); } // A helperfunction for the ajaxInterception to work in Chrome function addJS_Node (text, s_URL, funcToRun) { var D = document; var scriptNode = D.createElement('script'); scriptNode.type = "text/javascript"; if(text) scriptNode.textContent = text; if(s_URL) scriptNode.src = s_URL; if(funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()'; var targ = D.getElementsByTagName('head')[0] || D.body || D.documentElement; targ.appendChild(scriptNode); } // This function is necessary to intercept the ajax addJS_Node(null, null, interceptAjax); inject(injection); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload