我有一個ajaxCall函數刪除圖像,如果操作成功完成,將調用另一個函數,用於刪除顯示圖像的div
。如何檢索通過PHP傳遞的JavaScript對象?
在被傳遞到PHP變量,我嘗試傳遞包含圖像div
對象,並在成功的功能我想檢索該對象由JavaScript將其刪除。但實際上我不知道這是可能的還是不可能的?!我有這樣的錯誤:TypeError: $object.parent is not a function
這是我的代碼:
HTML
<div>
<input type="hidden" name="imageID" id="imageID" value="1">
<a href="#">
<img src="a.jpg" alt="">
</a>
<a class="del-btn-pic" href="#">Delete</a>
</div>
的JavaScript
$(document).on("click",".del-btn-pic", function() {
$this = $(this);
var imageID = $this.parent().children('input').val();
var divObject = JSON.stringify($this);
ajaxCall('deleteImage', {object:divObject , imageID:imageID }, removeImageVisual)
});
function removeImageVisual(data) // -> This function after ajaxCall is called. the php code in success returns the div object which passed before, and in failure returns 0.
{
if(data != 0)
{
$divObject = JSON.parse(data);
$divObject.parent().remove();
}
else
{
alert('Error!');
}
}
其實,在我的代碼,我通過了'標籤'的對象,並檢索它(不'div'標籤) – Highlan 2014-09-23 06:49:18
它看起來很好untils的$ divObject.parent(),你是什麼人。試圖達到那個目標? $ divObject必須是像{'name':'Javier'}這樣的json對象,並且它肯定沒有父對象。 – Balder 2014-09-23 06:50:05
@Balder正如我在我的評論中所說的,不幸的是,代碼與我的問題有點不同!實際上devObject是'a'標籤! – Highlan 2014-09-23 06:53:24