Şu şekilde yapmaya calısıyorum fakat olmuyor. Elimde 1 adet form bulunmaktadır bu formları post edince ilgili URL'ye valueleri post etmesini istiyorum bir türlü yapamadım.
<script>
function SendData() {
const tkn = document.getElementsByName('tkn').value;
const http = new XMLHttpRequest();
const url = 'get_data.php';
const params = "tkn=" + tkn + "";
http.open('POST', url, true);
// Send the proper header information along with the request
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.onreadystatechange = function () { // Call a function when the state changes.
if (http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
};
http.send(params);
console.log(tkn);
}
</script>
document.getElementsByName fonksiyonu sana doğrudan objeyi döndürmez. Objelerin bulunduğu bir array döndürür. Yapman gereken bu array içerisinden objeyi seçmek. Yani örneğin ilk tkn isimli inputu alacaksan;
const tkn = document.getElementsByName('tkn')[0].value;şeklinde bu satırı düzeltmen gerekli.
Yardımcı olduysam R10+ kullanmayı unutma.