0

I've an Ajax code, through which i want to send securely a private access_token to a url via http POST, how to achieve this using below given code??

function getstatus(url, placeid, access_token)
        {
            if(window.XMLHttpRequest)
            {
                xmlRequest = new XMLHttpRequest();
            }
            else if(window.ActiveXObject)
            {
                try
                {
                xmlRequest = new ActiveXObject("Msxm12.xMLHTTP");
                }
                catch(e)
                {
                    try 
                    {
                    xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    catch(e)
                    {
                        xmlRequest = false;
                    }
                }
            }


            xmlRequest.open("GET",url,true);
            xmlRequest.onreadystatechange = function()
                                    {
                                        if(xmlRequest.readyState==4)
                                        {
                                            if(placeid == "adminstatus")
                                            adminstatus.innerHTML=xmlRequest.responseText;

                                            if(placeid == "dbview")
                                            {
                                            dbview.innerHTML=xmlRequest.responseText;
                                            }
                                        }
                                    }
            xmlRequest.send();
        }

Consider the parameter "access_token" in the function getstatus is to be http POST-ed!

1
  • Why don't you want to use jQuery? It will shield you from browser differences which can be a huge pain and barrier for your development. As a second remark, if you want to send a private token, you should certainly do it over https and not http. Commented Jan 2, 2013 at 16:24

1 Answer 1

1

Take a look at XMLHttpRequest, assuming you are attempting to send the data as key/value pairs,

xmlRequest.open("POST",url,true);//use the post method
xmlRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");//set the content type
...
xmlRequest.send("access_token="+encodeURIComponent(access_token));//send the token
Sign up to request clarification or add additional context in comments.

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.