Problem with making a simple JS XmlHttpRequest call

Posted by recipriversexclusion on Stack Overflow See other posts from Stack Overflow or by recipriversexclusion
Published on 2010-04-19T21:44:08Z Indexed on 2010/04/19 21:53 UTC
Read the original article Hit count: 179

Filed under:
|
|

I have to create a very simple client that makes GET and POST calls to our server and parses the returned XML. I am writing this in JavaScript, problem is I don't know how to program in JS (started to look into this just this morning)!

As n initial test, I am trying to ping to the Twitter API, here's the function that gets called when user enters the URL http://api.twitter.com/1/users/lookup.xml and hits the submit button:

function doRequest() {
    var req_url, req_type, body;
    req_url = document.getElementById('server_url').value;
    req_type = document.getElementById('request_type').value;   
    alert("Connecting to url: " + req_url + " with HTTP method: " + req_type);
    req = new XMLHttpRequest();
    req.open(req_type, req_url, false, "username", "passwd");// synchronous conn
    req.onreadystatechange=function() {
            if (req.readyState == 4) {
                    alert(req.status);
            }
    }
    req.send(null);
}

When I run this on FF, I get a

Access to restricted URI denied" code: "1012

error on Firebug. Stuff I googled suggested that this was a FF-specific problem so I switched to Chrome. Over there, the second alert comes up, but displays 0 as HTTP status code, which I found weird.

Can anyone spot what the problem is? People say this stuff is easier to use with JQuery but learning that on top of JS syntax is a bit too much now.

© Stack Overflow or respective owner

Related posts about xmlhttprequest

Related posts about JavaScript