使用纯javascript通过AJAX发布时,Textarea为空
当我试图发布这个文本区域时,它不发送任何内容,并且显然不返回任何内容 所有其他输入字段都可以 我已经读过了,每个人都说要确保。值是在getelementid之后添加的,我无论如何都在这样做,所以我不确定是什么错了 我用的是Bootstrap3,以防万一 更新:我刚刚做了一个测试,将文本硬编码到textarea字段中。成功地通过了。但是我在表单中键入的任何文本都不会被传递。我想这可能是Bootstrap3的错误 还有人知道吗 Javascript: HTML使用纯javascript通过AJAX发布时,Textarea为空,javascript,ajax,Javascript,Ajax,当我试图发布这个文本区域时,它不发送任何内容,并且显然不返回任何内容 所有其他输入字段都可以 我已经读过了,每个人都说要确保。值是在getelementid之后添加的,我无论如何都在这样做,所以我不确定是什么错了 我用的是Bootstrap3,以防万一 更新:我刚刚做了一个测试,将文本硬编码到textarea字段中。成功地通过了。但是我在表单中键入的任何文本都不会被传递。我想这可能是Bootstrap3的错误 还有人知道吗 Javascript: HTML 但事实上,文本区域没有任何价值。在发送
但事实上,文本区域没有任何价值。在发送之前,您在其中写了什么吗?我看到您使用的是Bootstrap3,如果您想使用他们的javascript插件,它需要jQuery。您希望通过普通JavaScript而不是更跨浏览器的解决方案jQuery来实现这一点,有什么特别的原因吗?@Florian,数据将在填充文本区域后发送。@lightswitch05我的ajax解决方案不是插件,这就是为什么我使用普通JavaScript通过ajax发布数据。您收到任何警报吗?我建议你去掉代码中的所有内容,但至少保留表单、按钮和文本区域。试着让它工作,首先只是提醒您它的值,然后通过提交操作函数传递它,然后发布它。只有到那时,再加上剩下的。
var http_request = false;
function show_hint(p_hint_text, p_span) {
document.getElementById(p_span).innerHTML = p_hint_text;
}
function makePOSTRequest(url, parameters, SpanName) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function () {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById(SpanName).innerHTML = result;
document.getElementById(StatusName).innerHTML = 'Ready';
} else {
alert('There was a problem with the request.');
}
}
};
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
alert(parameters);
http_request.send(parameters);
}
function Contact(obj, SpanName, StatusName) {
var curDateTime = new Date(); //For IE
var poststr = "gid=" + encodeURI(document.getElementById("gid").value) +
"&tid=" + encodeURI(document.getElementById("tid").value) +
"&cid=" + encodeURI(document.getElementById("cid").value) +
"&recid=" + encodeURI(document.getElementById("recid").value) +
"&item_ip=" + encodeURI(document.getElementById("item_ip").value) +
"&item_userid=" + encodeURI(document.getElementById("item_userid").value) +
"&item_author=" + encodeURI(document.getElementById("item_author").value) +
"&fromajax=" + encodeURI(document.getElementById("fromajax").value) +
"&action=" + encodeURI(document.getElementById("action").value) +
"&active=" + encodeURI(document.getElementById("active").value) +
"&message=" + encodeURI(document.getElementById("message").value);
var SpanName = SpanName;
var StatusName = StatusName;
//alert (SpanName);
alert(poststr);
makePOSTRequest('http://fakedomain.com', poststr, SpanName);
}
<span id="ContactFormSpanQXBIAHOBEU25">
<span id="statusQXBIAHOBEU25">
<form role="form" action="javascript:Contact(document.getElementById('ContactForm'),'ContactFormSpanQXBIAHOBEU25','statusQXBIAHOBEU25'); show_hint('Sending Data, Please Wait...', 'statusQXBIAHOBEU25');" method="post" name="ContactForm" id="ContactForm">
<input name="gid" id="gid" type="hidden" value="SDZOAYLTDV26">
<input name="tid" id="tid" type="hidden" value="ZBSAGNSCFM55">
<input name="cid" id="cid" type="hidden" value="2">
<input name="recid" id="recid" type="hidden" value="QXBIAHOBEU25">
<input name="item_IP" id="item_ip" type="hidden" value="555.555.555.555">
<input name="item_userid" id="item_userid" type="hidden" value="YCGLNBFZPD13">
<input name="item_author" id="item_author" type="hidden" value="YCGLNBFZPD13">
<input name="fromajax" id="fromajax" type="hidden" value="1">
<input name="action" id="action" type="hidden" value="add">
<input name="active" id="active" type="hidden" value="1">
<div class="form-group">
<textarea class="form-control" name="message" id="message" rows="5"></textarea>
</div>
<input name="Submit2" type="submit" class="btn btn-success btn-flat" value="Submit" />
</form>
</span>
</span>