weixin_33719619 2015-05-24 15:38 采纳率: 0%
浏览 31

使用AJAX进行GET和POST

So Im new to web programing, I need to GET an HTML page, containing a Form that I want to send via POST, this is what I tried so far:

<script>
var msgpost=new XMLHttpRequest();
msgpost.open("GET","http://localhost/elgg/pg/messages/compose",false);
msgpost.send();
alert("fine");
document.addEventListener("DOMContentLoaded", function(){
    alert("fine2");
    var hidden1=document.getElementByName("__elgg_token").value;
    var hidden2=document.getElementByName("__elgg_ts").value;
    alert("fine3");
    alert("sending hidden1 "+hidden1+" 2 "+hidden2);
    msgpost.open("POST","http://localhost/elgg/action/messages/send",true);
    msgpost.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    msgpost.send("__elgg_token="+hidden1+"&__elgg_ts="+hidden2+"&message=PWND&send_to=9&title=PWND");
    alert("done.");
},false);
</script>

"__elgg_token" and "__elgg_ts" are hidden input fields that I need to get their value to POST to the server from /compose. So I get "fine" and "fine2", the rest is not working and FireBug isn't showing any POST messages outgoing. Any Ideas?

  • 写回答

1条回答 默认 最新

  • weixin_33744141 2015-05-24 15:55
    关注

    I think you should use

    var hidden1 = document.getElementsByName("__elgg_token").value;
    var hidden2 = document.getElementsByName("__elgg_ts").value;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭