如何获取ajax请求响应中存在的图像的位置,并使用位置绘制线

How to take the position of images that are present in the response of ajax request and using the position draw lines

本文关键字:位置 图像 绘制 存在 何获取 获取 响应 请求 ajax      更新时间:2023-09-26

如何在jquery ajax调用完全完成并将响应完全加载到浏览器中之后才进行js函数调用。我正在尝试将ajax调用的响应加载到div标记中。

加载响应后,我想确定ajax调用响应中出现的图像的位置。使用该位置,我将在同一div标记中的图像之间绘制线。

问题是:在浏览器中完全呈现ajax响应之前,会调用js函数,并使用错误的位置绘制线条。

function loadMap(formId, url, divID)
{
    event.preventDefault();
    var values = $("#"+formId).serialize();
    openDialog();
    $.ajax({
        url : url,
        type : "post",
        data : values,
         async: false,
         cache: false,
        success : function(result) 
        {
            closeDialog();
            $("#"+divID).html(result);
        },
        error : function()
        {
            loadSessionExpiredPage();
        },
    });
    alert("Ajax call Completed");
        drawMap(); // Taking the position of images from response text and Draw lines in the  div tag where a loaded the response text.
}

您可以使用setTimeOut在Ajax响应的成功部分编写drawMap()方法调用。

success : function(result) 
{
    closeDialog();
    $("#"+divID).html(result);
    setTimeout(function() {
        drawMap();
    }, 1000);
},

在您调用的浏览器中加载图像后调用loadmap,但图像没有加载,因此您无法获得正确的位置

结果出来后使用加载

$('<img/>').load(function(){ // in this you call your function });