views:

75

answers:

2

Should this code not work? I actually have no idea how to use this HTTP request thing.

<script language="javascript">
function HTTPCALL()
{
    var request = HTTP.newRequest();
    request.open("POST", "https://workplace.intuit.com/db/main", false);
    request.setRequestHeader("Content-Type", "application/xml");
    request.setRequestHeader("QUICKBASE-ACTION", "API_GetUserInfo");
    request.send( 
    '<qdbapi>
        <apptoken>c4abnsde36pse7hzurwvjjb4m</apptoken>
        <email>[email protected]</email>
    </qdbapi>' 
    ); 
}
</script>

For me, nothing happens. I tried putting an alert anywhere in the function and it never shows. Help!

+2  A: 

You cannot use AJAX to send requests to a different domain.
Instead, you can make a server-side proxy on your server that forwards the request to Intuit and relays the response back to the client.

You also have a syntax error - strings cannot span multiple lines.
Therefore, your code won't even parse, let alone execute.

SLaks
is there a way to accomplish this, then?
Jimmy
Only if you work for Intuit.
SLaks
There has to be some way to send a post to another domain. I'm working on "federating" this web app i've built with the Intuit platform, and in order to do so, you have to post XML to them.
Jimmy
@Jimmy: You could have this script contact a local server-side script, that in turn contacts the Intuit web service you are trying to hook into. Then, that script would in turn send data back to your web page. This is assuming you have the proper permissions to access Intuit's API. This also assumes that your JavaScript is functional, which I am not addressing here.
Jeff Fohl
+1  A: 

There isn't any standard object called HTTP. Look back at wherever you got this code: it's using a third-party library and you can probably download it there.

In any case, it's just a function definition. You never execute it.

BTW, the standard tag for JavaScript code is:

<script type="text/javascript"></script>
Álvaro G. Vicario