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,776
  • 2
  • 25
  • 43

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);
edinvnode
  • 3,497
  • 7
  • 30
  • 53
  • 1
    Thank you IceD, But Would you be able to elaborate little more with actual code please. – Vikash Rathee Nov 27 '13 at 04:39
  • There you go. But I don't know will this code work since I didn't test it. – edinvnode Nov 28 '13 at 09:22
  • Try out this solution. I noticed it has similarities with your question. http://stackoverflow.com/questions/11579587/include-jquery-into-javascript-and-use-it-in-imacros/20147634#20147634 – edinvnode Nov 29 '13 at 16:31