- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我读了很多关于用 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/
我是一名优秀的程序员,十分优秀!