我想在xhr.responseText中搜索id为“something”的div,然后从该div中包含的xhr.responseText中删除所有内容。
这是我的xhr代码:
std::string str = getSomeStr();
std::string str2 = getSomeOtherStr();
std::string *captured_str;
auto lambda = [&captured_str](const std::string* b){return *str + "abc" == b;}
captured_str = &str;
auto it = std::find_if(vec.begin(), vec.end(), lambda);
captured_str = &str2;
auto it = std::find_if(vec.begin(), vec.end(), lambda);
在此处删除div:
function getSource(source) {
var url = source[0];
var date = source[1];
/****DEALS WITH CORS****/
var cors_api_host = 'cors-anywhere.herokuapp.com';
var cors_api_url = 'https://' + cors_api_host + '/';
var slice = [].slice;
var origin = self.location.protocol + '//' + self.location.host;
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function () {
var args = slice.call(arguments);
var targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1]);
if (targetOrigin && targetOrigin[0].toLowerCase() !== origin &&
targetOrigin[1] !== cors_api_host) {
args[1] = cors_api_url + args[1];
}
return open.apply(this, args);
};
/****END DEALS WITH CORS****/
var xhr = new XMLHttpRequest();
xhr.open("GET", cors_api_url+url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var resp = xhr.responseText;
var respWithoutDiv = removeErroneousData(resp);
}
else{
return "Failed to remove data.";
}
}
xhr.send();
}
答案 0 :(得分:0)
您可以将响应转储到div中,然后搜索要清空其内容的div。
xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ var resp = xhr.responseText; $(' div')。attr(' id',' resp')。html(resp); $('#RESP')。找到('披露')HTML('')。 // var respWithoutDiv = removeErroneousData(resp); } 其他{ 返回"无法删除数据。&#34 ;; } }