0

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!

4
  • you got me. I found this code. I'm just trying to manually piece together a post and send it. Commented Jun 23, 2010 at 20:24
  • Quickbase-action is part of the post. i'm calling to a quickbooks API. Commented Jun 23, 2010 at 20:24
  • 2
    The HTTP.newRequest() business is from an O'Reilly Javascript book; it's an Ajax wrapper. Presumably you'd be better off using an Ajax library such as jQuery. But it won't work anyway because of the same-origin policy (i.e. you can't send a request to a different domain). Commented Jun 23, 2010 at 20:28
  • A POST for something called GetUserInfo. I love it. Commented Jun 23, 2010 at 20:28

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

is there a way to accomplish this, then?
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: 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.
1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.