I have XULrunner opening a browser window that loads a XUL page from my local server. I am trying to post some data back to my PHP but with little success. I am just using the example at https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Post_data_to_window
Here's what my javascript looks like
var params = obj.getAttribute('params');
var url = obj.getAttribute('url');
alert(params + ' - ' + url);
const Cc = Components.classes;
const Ci = Components.interfaces;
var stringStream = Cc['@mozilla.org/io/string-input-stream;1'].createInstance(Ci.nsIStringInputStream);
stringStream.data = params;
var postdata = Cc['@mozilla.org/network/mime-input-stream;1'].createInstance(Ci.nsIMIMEInputStream);
postdata.addHeader('Content-Type', 'application/x-www-form-urlencoded');
postdata.addContentLength = true;
postdata.setData(stringStream);
document.getElementById('mainbrowser').loadURI(url, null, postdata, null);
Without trying to confuse the matter too much, this is obviously part of a much bigger picture. The only part not shown, that is relevant, is where obj
is derived. Basically it is a temporary XUL element that has all the parameters stored in it for easy access as I pass them around to different functions in my javascript. Also the params
is in the format of name1=data1&name2=data2
.
I know it is working up to the alert
as it does outputs the parameters that I am sending. I am also sure the browser is being reloaded as the data I entered in the form is being cleared each time I submit it. But in my PHP if I output the contents of $_POST
there is nothing.
I did have this working using XMLHttpRequest but it wasn't ideal for how I needed things to work. So I am hoping to get his method working.