0

我有一个 Ajax 代码,我想通过它通过 http POST 安全地将私有 access_token 发送到 url,如何使用下面给定的代码来实现这一点?

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();
        }

考虑函数getstatus中的参数“access_token”是http POST-ed!

4

1 回答 1

1

看看XMLHttpRequest,假设您尝试将数据作为键/值对发送,

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
于 2013-01-02T16:49:39.873 回答