我正在尝试在HTML元素中编写一些输入并使用JS获取输入文本,然后使用AJAX将值发送到另一个文件,但它不起作用,我只得到“null”作为结果
有原因吗?
这是我的HTML
<button type="button" onclick="loadDoc()">Value</button>
<input type="number" class="test" id="test" name="test" value="" style="width:10%" >
<div id="mostraAttuale"></div>
</br>
这是我的JS功能
function loadDoc() {
var value = document.getElementById("test");
alert(value);
var url = <?php echo json_encode($test); ?>;
var email = <?php echo json_encode($mail); ?>;
var valuereq = new XMLHttpRequest();
valuereq.open("GET", url+'?email='+email+'&value='+value, true);
valuereq.send();
valuereq.status;
valuereq.onreadystatechange = function () {
if (valuereq.readyState == 4 && valuereq.status == 200) {
var return_data = valuereq.responseText;
document.getElementById("mostraAttuale").innerHTML = "ultimo valore inserito: " + return_data;
}
else document.getElementById("mostraAttuale").innerHTML = valuereq.status;
}
document.getElementById("test").value="";
}
提前谢谢。
答案 0 :(得分:3)
试试这个:
function loadDoc() {
var value = document.getElementById("test").value;
alert(value);
var url = "<?=json_encode($test) ?>";
var email = "<?=json_encode($mail) ?>";
var valuereq = new XMLHttpRequest();
valuereq.open("GET", url+'?email='+email+'&value='+value, true);
valuereq.send();
valuereq.status;
valuereq.onreadystatechange = function () {
if (valuereq.readyState == 4 && valuereq.status == 200) {
var return_data = valuereq.responseText;
document.getElementById("mostraAttuale").innerHTML = "ultimo valore inserito: " + return_data;
}
else
document.getElementById("mostraAttuale").innerHTML = valuereq.status;
}
document.getElementById("test").value="";
}
答案 1 :(得分:2)
行var function Test-GroupMembership {
Param(
[Parameter(Mandatory=$true)]
[string]$Identity,
[Parameter(Mandatory=$true)]
[string]$Name
)
$groups = Get-ADPrincipalGroupMembership -Identity $Identity
if ($groups | Where-Object { $_.Name -like $Name }) {
return $true
} elseif ($groups -ne $null) {
foreach ($g in $groups) {
if (Test-GroupMembership -Identity $g -Name $Name) {
return $true
}
}
}
return $false
}
没有获得值,而是“HTMLInputElement”。替换为:
value = document.getElementById("test");