gpt4 book ai didi

javascript - 通过ajax发送长字符串不起作用

转载 作者:行者123 更新时间:2023-11-28 16:03:21 24 4
gpt4 key购买 nike

我正在尝试通过ajax将一个长字符串发送到php页面,该页面将处理它并返回我需要的内容,我认为它超出了GET容量或类似的东西!但由于某种原因它不起作用

var string = document.getElementById('text').innerHTML; // so long text
var xhr = new XMLHttpRequest();
xhr.open('GET', 'read.php?string=' + string, true);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.status == 200 && xhr.readyState == 4) {
content.innerHTML = xhr.responseText;
} else {
content.innerHTML = 'loading';
}
}

我怎样才能让它发挥作用!

最佳答案

只需替换:

xhr.open('GET', 'read.php?string=' + string, true);
xhr.send();

var body = "string=" + encodeURIComponent(string);
xhr.open("POST", "read.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-Length", body.length);
xhr.setRequestHeader("Connection", "close");
xhr.send(body);

关于javascript - 通过ajax发送长字符串不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16159932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com