3

I was making a automation script to extract some info from a website, And It's important to submit some info using POST method. Can anyone tell me how to use HTTP Post method with Imacro & javascript for firefox plugin. Below is the script which i found here : Sending an HTTP Post using Javascript triggered event But it's giving me error when i play the same using Imacro player.

var url = "http://www.google.com/";
var method = "POST";
var postData = "Some data";
var async = true;

var request = new XMLHttpRequest();
request.onload = function () {
var status = request.status; // HTTP response status, e.g., 200 for "200 OK"
var data = request.responseText; // Returned data, e.g., an HTML document.
}

request.open(method, url, async);

request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.send(postData);
Community
  • 1
  • 1
Vikash Rathee
  • 1,576
  • 2
  • 21
  • 37

2 Answers2

5

XMLHttpRequest() is no longer supported in firefox 15+

You have to define it:

const XMLHttpRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1");
var request = XMLHttpRequest();
Poker Joker
  • 382
  • 2
  • 8
0

To run JavaScript in iMacros you can use this method.

URL GOTO=javascript:window.ScrollTo(0,150);

Try this method.

In your case it would look like this.

URL GOTO=javascript:var url = "http://www.google.com/";var method = "POST";var postData = "Some data";var async = true;var request = new XMLHttpRequest();request.onload = function () var status = request.status; var data = request.responseText; request.open(method, url, async);request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");request.send(postData);
macroscripts
  • 3,459
  • 7
  • 28
  • 49