Reputation: 490
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?
Upvotes: 0
Views: 161
Reputation: 105
I think you should use
var hidden1 = document.getElementsByName("__elgg_token").value;
var hidden2 = document.getElementsByName("__elgg_ts").value;
Upvotes: 1