How do you make a post request into a new browser tab using JavaScript / XUL?

By : aryeh

I'm trying to open a new browser tab with the results of a POST request. I'm trying to do so using a function containing the following code:

var windowManager = Components.classes[";1"]
var browserWindow = windowManager.getMostRecentWindow("navigator:browser");
var browser = browserWindow.getBrowser();
if(browser.mCurrentBrowser.currentURI.spec == "about:blank")
    browserWindow.loadURI(url, null, postData, false);
    browser.loadOneTab(url, null, null, postData, false, false);

I'm using a string as url, and JSON data as postData. Is there something I'm doing wrong?

What happens, is a new tab is created, the location shows the URL I want to post to, but the document is blank. The Back, Forward, and Reload buttons are all grayed out on the browser. It seems like it did everything except executed the POST. If I leave the postData parameter off, then it properly runs a GET.

Build identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv: Gecko/2008070206 Firefox/3.0.1

By : aryeh


The answer to this was found by shog9. The postData parameter needs to be a nsIMIMEInputStream object as detailed in here.

By : aryeh

The proper way to sort strings is:

import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') # vary depending on your lang/locale
assert sorted((u'Ab', u'ad', u'aa'), cmp=locale.strcoll) == [u'aa', u'Ab', u'ad']

# Without using locale.strcoll you get:
assert sorted((u'Ab', u'ad', u'aa')) == [u'Ab', u'aa', u'ad']

The previous example of mylist.sort(key=lambda x: x.lower()) will work fine for ASCII-only contexts.

If you're familiar with Python, check out the Twisted framework.

By : Vasil

This video can help you solving your question :)
By: admin