Jimmy
Jimmy

Reputation: 2925

HTTP request in Javascript

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!

Upvotes: 0

Views: 602

Answers (2)

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146563

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>

Upvotes: 1

SLaks
SLaks

Reputation: 888047

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.

Upvotes: 2

Related Questions