gpt4 book ai didi

javascript - 无法替换responseText中的反斜杠?

转载 作者:行者123 更新时间:2023-11-28 02:00:11 25 4
gpt4 key购买 nike

我读了很多关于用 javascript 替换反斜杠的问题,并尝试了它们,但它们对我不起作用。响应文本包含反斜杠,我需要删除它们,但没有任何效果?这是发出请求的 JS 函数:

  requestKittens: function() {
var req = new XMLHttpRequest();

req.onreadystatechange = function (event) {
var xhr = event.target;


if (xhr.readyState === 4 && xhr.status === 200) {
var str = xhr.responseText;
str.replace(/\\/g, '');
document.getElementsByTagName('body')[0].innerHTML = xhr.responseText

}
};

req.open('GET', this.searchOnFlickr_, true);
req.setRequestHeader('accessKey','fdsfkslfjslfjlgfdgdfg');


req.send();
},

这是服务器的响应

{"topics":[{"topicLabel":"Computer concepts","topicThesaurusName":"topics","topicUrl":"http://dictionary.cambridge.org/topics/technology/computer-concepts/","topicId":"computer-concepts","topicParentId":"technology"}],"dictionaryCode":"british","entryLabel":"address noun (COMPUTERS)","entryContent":"address</h1> noun</span> [C</span></span>]</span></span> (COMPUTERS)</span>https://dictionary.cambridge.org/external/images/uk_pron.png?version=2013-08-07-1929\"/></a>https://dictionary.cambridge.org/media/british/uk_pron/u/uka/ukada/ukadapt021.mp3\"/>https://dictionary.cambridge.org/media/british/uk_pron_ogg/u/uka/ukada/ukadapt021.ogg\"/>Your browser does not support HTML5 audio.</audio>https://dictionary.cambridge.org/external/images/us_pron.png?version=2013-08-07-1929\"/></a>https://dictionary.cambridge.org/media/british/us_pron/e/eus/eus70/eus70074.mp3\"/>https://dictionary.cambridge.org/media/british/us_pron_ogg/e/eus/eus70/eus70074.ogg\"/>Your browser does not support HTML5 audio.</audio> /əˈdres</span>/</span>  /ˈæd.res</span>/</span> </span></header>A1</span> </span>a series of letters and symbols that tell you where to find something on the internet or show where an email is sent to: </span></span>What's your email address?</span></span>Do you have their Web address?</span></span></section> \u203a</span> specialized</span></span></span> the place where a piece of information is stored in a computer's memory</span></span></section>(Definition of address noun (COMPUTERS) from the https://dictionary.cambridge.org/dictionary/british/\" title=\"Cambridge Advanced Learner's Dictionary & Thesaurus\n\">Cambridge Advanced Learner's Dictionary & Thesaurus\n</a> © Cambridge University Press)</small></footer></article>","entryUrl":"http://dictionary.cambridge.org/dictionary/british/address_2","format":"html","entryId":"address_2"}

什么可能导致这个问题?

最佳答案

尝试:

str = str.replace(/\\/g, '');

还有:

document.getElementsByTagName('body')[0].innerHTML = str;

关于javascript - 无法替换responseText中的反斜杠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18547372/

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