Vikash Rathee
Vikash Rathee

Reputation: 2064

HTTP post in iMacros with Javascript for Firefox

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);

Upvotes: 3

Views: 4819

Answers (2)

Poker Joker
Poker Joker

Reputation: 382

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();

Upvotes: 5

edinvnode
edinvnode

Reputation: 3537

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);

Upvotes: 0

Related Questions