[英]AJAX request not sending complete data in php page
I have been trying to post a status in my web application through AJAX which is sending a request to a PHP page and PHP page processes information furthermore.我一直在尝试通过 AJAX 在我的 Web 应用程序中发布状态,AJAX 向 PHP 页面发送请求,PHP 页面进一步处理信息。
function Upload_Status(id){
var description=$('#Txt-editor').val();
var data="q="+description;
var xhr = new XMLHttpRequest();
xhr.open('POST', 'status.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
var response=this.responseText;
if (!(response=="" || response==null)) {
document.getElementById(id).innerHTML = response;
}
};
xhr.send(data);
}
And status.php is而status.php是
echo $_POST['q'];
which returns sometime half string and something quarter.有时返回半字符串和四分之一的东西。 I don't know what the problem is as I'm using a text editor, I also have changed editor but when this generates HTML code this creates the problem.
我不知道问题是什么,因为我使用的是文本编辑器,我也更改了编辑器,但是当它生成 HTML 代码时,就会产生问题。
Any help?有什么帮助吗?
I solved this questions myself.我自己解决了这个问题。 the problem was with the special symbols,commas and quotation signs etc. If i encrypt information sending from JS and decode JSON response and which return response from PHP i encode this response again to JSON, then this problem is solved :-)
问题出在特殊符号、逗号和引号等。如果我加密从 JS 发送的信息并解码 JSON 响应并从 PHP 返回响应,我将此响应再次编码为 JSON,那么这个问题就解决了:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.