[英]Unable to strip img tag from jQuery ajax response
我有一個Web應用程序,將ajax發布到PHP腳本,返回一堆html。 在html中有一個圖像和一個數據表。 我想做的是將圖像與html的其余部分分開,以便可以在其他地方顯示它。
$.ajax({
type: "POST",
url: 'api/service_connector.php',
data: { selectedmodel: requestdata },
beforeSend: function() {},
success: function(returneddata) {
var $response=$(returneddata);
var test = $response.filter('.testimage').html();
alert(test);
}
});
如果在我的成功函數中,我只是警告整個returndata變量,則一切正常。 因此,我知道該職位本身正在運作,一切都已正確退還; 只需抓住我面對的圖像標簽即可。 我還嘗試了在Google上找到的其他“方式”。 例如,
alert($(returneddata).find('.testimage').html());
嘗試detach()
$.ajax({
type: "POST",
url: 'api/service_connector.php',
data: { selectedmodel: requestdata },
beforeSend: function() {},
success: function(returneddata) {
var $response=$(returneddata);
var $testimage = $response.find('.testimage');
$testimage.detach();
alert($('<p>').append($response).html());
}
});
你玩過jquery的$.remove()
嗎?
例如:
<div class="container">
<img class="theimage" src=".." />
</div>
...
$(".theimage").prop("src"); // get anything valuable from image first for future use
$(".theimage").remove(); // remove the image from there
在php文件中
在表格數據的首尾添加一個分隔符('|')
在ajax功能
獲取“ |”之間的內容 符號。
就像你也可以為圖像標簽做的一樣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.