I used the program Postman to send a HTTP Post request for me. It works fine with Postman, meaning it does send correctly.

Now I try to use Postman's generate code snippets to convert the request's code to JavaScript jQuery AJAX and put the result into a userscript:

// ==UserScript==
// @name         Send HTTP
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://colorillo.com/
// @grant        none
// ==/UserScript==
var timerVar = setInterval (function() {DoMeEverySecond (); }, 5000); // << set to 2 seconds.

function DoMeEverySecond ()
{
var form = new FormData();
form.append("l", "[[158,115],[159,115],[159,116],[160,118],[161,119],[161,120],[162,121],[162,122]]");
form.append("w", "1");
form.append("c", "000000");
form.append("o", "100");
form.append("f", "1");
form.append("_", "false");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://colorillo.com/draw.php?ing=_index",
  "method": "POST",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "X-Requested-With": "XMLHttpRequest",
    "Accept": "*/*",
    "User-Agent": "PostmanRuntime/7.11.0",
    "Cache-Control": "no-cache",
    "Postman-Token": "c6ecb194-94ba-4945-88fa-8d8cab3a1bd4,c20b3c71-cc61-4874-93c4-2f3c6b63d5b6",
    "Host": "colorillo.com",
    "cookie": "i=cloyfj1bio8uvxlqrkfkczqxo1pmx7m5; o=100; w=15; c=t44q; h=_-g00000____5aU00bH_GqCFXg3g_SY0gtx1J808RNApYLbO6g41X1wo____T000R01Puw3rMVU0t44q7w3F0afp4NcjXz00; a=lnpe0l; oi=qld8gxkfrzalpvqgydze7dzbm8p1r2zp",
    "accept-encoding": "gzip, deflate",
    "content-length": "753",
    "Connection": "keep-alive",
    "cache-control": "no-cache"
  },
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
})();
}

Running the above code in TamperMonkey doesn't send the request, and shows an error in console:

enter image description here

The site uses jQuery, I can confirm that from devtools console.

1 Answers

0
wOxxOm On

The site is using jQuery v1.4.2, but done() was added in 1.5.

Use success callback inside settings instead:

var settings = {
  "success": function (data) {
    console.log(data);
  },
  "async": true,
  "crossDomain": true,
  "url": "http://colorillo.com/draw.php?ing=_index",
  //.......................
}

$.ajax(settings);