html 第二次未调用函数[已关闭]

2admgd59  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(152)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
11小时前关门了。
Improve this question
当我第一次调用Javascript函数时,它工作正常,但第二次调用时出现错误,如

Uncaught TypeError: profile is not a function at HTMLImageElement.onclick

为什么会这样
尝试在html和js文件的头部分写入函数,但不起作用!

function profile_detail(){

    xhr = new XMLHttpRequest();
    xhr.open("POST", "http://localhost/CI-social-media/index.php/profile_detail", false);

    xhr.onload = () => {
        if (xhr.status == 200) {

        if (xhr.response) {
            profile = JSON.parse(xhr.responseText);
            // console.log(xhr.response);
            console.log(xhr.response);
            console.log(profile);

                // document.getElementById("profile_photo").innerHTML =xhr.response;
                document.getElementById("profile_photo").src = profile[0]["profile"];
                document.getElementById("profile_name").innerHTML = profile[0]["display_name"];
                document.getElementById("username").innerHTML = "@"+ profile[0]["user_name"];
                
            }
            else {
                alert("something want wrong try agin later")
            }
        }
        else {
            alert("Something Want Wrong Try agin");
        }
    }

    xhr.send();
}

function profile(){

    document.getElementById("request").style.display="none";
    document.getElementById("friend_list").style.display="none";
    document.getElementById("msg_section").style.display="none";
    document.getElementById("friend_search").style.display="none";
    document.getElementById("home_mains").style.display="none";
    document.getElementById("search_friend_main").style.display="none";
    document.getElementById("search1").style.display="none";
    document.getElementById("rrprofile-card").style.display="flex";
    profile_detail();
    
    
}
yzuktlbb

yzuktlbb1#

有很多原因

1. In first time call the function it's remove the itself ( function )

For example you use innerHtml = "" in head section 
    
sometimes happening

2. You use a same name for variable and function

Mostly having this error

相关问题