Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

second time function not calling

when i call Javascript function first time it work properly but second time it get error like

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

why it happening?

try to write function in head section of html as well as js file but didn’t working!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    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();
    
    
}

>Solution :

There are many reasons for the that

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 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading