Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript document.link.href调用中传递标题参数_Javascript - Fatal编程技术网

在javascript document.link.href调用中传递标题参数

在javascript document.link.href调用中传递标题参数,javascript,Javascript,我正在实现浏览器javascript代码 我定义了一个链接,如下所示 document.location.href ="/cssp_authorization?user_name="+ Ext.JSON.encode(user_name); 当用户单击该链接时,呼叫将被定向到/acspp\u授权页面。但是,我还需要在这个GET请求中传递头信息。我该怎么做呢?我建议切换到POST请求,而不是标准XMLHTTPRequest的获取和使用方法: xmlhttp.open("POST","cssp_a

我正在实现浏览器javascript代码

我定义了一个链接,如下所示

document.location.href ="/cssp_authorization?user_name="+ Ext.JSON.encode(user_name);

当用户单击该链接时,呼叫将被定向到/acspp\u授权页面。但是,我还需要在这个GET请求中传递头信息。我该怎么做呢?

我建议切换到POST请求,而不是标准XMLHTTPRequest的获取和使用方法:

xmlhttp.open("POST","cssp_authorization",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("My-Header","My-Value");
xmlhttp.send("user_name="+ Ext.JSON.encode(user_name));

如果jquery是您的首选选项,您可以使用它。

头信息是否与HTTP头信息相同?你不能只用一个链接或位置就做到这一点。href。当GET同样可以胜任这项工作时,你为什么建议发表一篇文章?GET和POST也有语义价值,不可交换。原因有很多,这里有一些解释-如果你仔细阅读,你就会明白为什么你提供的POST请求被认为是无效的。你能指出你所指的确切位置吗?也许我解释一下会更好。OP不处理任何形式或数据。OP只想获得一个资源并随请求发送一个自定义头。因此,该职位无效。