我需要能够完成运行 doGET() 函数,该函数将在我保存我的博文之前删除我的新缩略图。有人告诉我 CALLBACK 是我需要的,但我认为我太愚蠢了,无法理解它是如何工作的:P 如何在 doGET() 函数完全完成后单击按钮?
$('#xmlbutton').click(function() {
doGET();
document.getElementById("save-post").click();
})
function doGET() {
// Get the URL of featured image
// Fetch the right Image URL from FEATURED image and rename it to the FOUR image instances... ;)
var src = $('#set-post-thumbnail img').attr('src');
var src = src.slice(0, -12);
var imgsrc = src + ".jpg";
var img1 = src + "_thumb_one.jpg";
var img2 = src + "_thumb_two.jpg";
var img3 = src + "_thumb_three.jpg";
// Put Url of Thumbnail Images in the Boxes
document.getElementById('imageurl').value = src ;
document.getElementById('thumb_url_1').value = '<img src="' + img1 + '">' ;
document.getElementById('thumb_url_2').value = '<img src="' + img2 + '">' ;
document.getElementById('thumb_url_3').value = '<img src="' + img3 + '">' ;
// Save the Draggable info, please!
var im1_top = document.getElementById('image_mover_1').style.top;
var im1_left = document.getElementById('image_mover_1').style.left;
document.getElementById('image1_adjust_top').value = im1_top;
document.getElementById('image1_adjust_left').value = im1_left;
var im2_top = document.getElementById('image_mover_2').style.top;
var im2_left = document.getElementById('image_mover_2').style.left;
document.getElementById('image2_adjust_top').value = im2_top;
document.getElementById('image2_adjust_left').value = im2_left;
var im3_top = document.getElementById('image_mover_3').style.top;
var im3_left = document.getElementById('image_mover_3').style.left;
document.getElementById('image3_adjust_top').value = im3_top;
document.getElementById('image3_adjust_left').value = im3_left;
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() //This part is actually executed last
{
if (xmlhttp.readyState==4 && xmlhttp.status==200) // Was the request processed successfully?
{
document.getElementById("sampleDiv").innerHTML=xmlhttp.responseText;
}
}
// Write the XML url string
var baseurl = "thumbgen.php?";
var left1 = "&left1=" + document.getElementById('image_mover_1').style.left;
var left2 = "&left2=" + document.getElementById('image_mover_2').style.left;
var left3 = "&left3=" + document.getElementById('image_mover_3').style.left;
var top1 = "&top1=" + document.getElementById('image_mover_1').style.top;
var top2 = "&top2=" + document.getElementById('image_mover_2').style.top;
var top3 = "&top3=" + document.getElementById('image_mover_3').style.top;
var imgwrap1 = "&imgwrap1=" + parseInt(document.getElementById('image_mover_1').getElementsByTagName('img')[0].offsetWidth);
var imgwrap2 = "&imgwrap2=" + parseInt(document.getElementById('image_mover_2').getElementsByTagName('img')[0].offsetWidth);
var imgwrap3 = "&imgwrap3=" + parseInt(document.getElementById('image_mover_3').getElementsByTagName('img')[0].offsetWidth);
var height1 = "&height1=" + document.getElementById('no_1_image').style.height;
var height2 = "&height2=" + document.getElementById('no_2_image').style.height;
var height3 = "&height3=" + document.getElementById('no_3_image').style.height;
var imgurl = "&imgurl=" + $('#image_mover_1 img').attr('src');
console.log( 'imgurl ~ ', imgurl );
var fullurl = baseurl + left1 + left2 + left3 + top1 + top2 + top3 + height1 + height2 + height3 + imgwrap1 + imgwrap2 + imgwrap3 + imgurl;
console.log('fullurl ~ ', fullurl );
xmlhttp.open('GET', fullurl );
xmlhttp.send();
};