Ajax Code not working although copied the exact thing from the video

I tried many times but the code doesn’t work and gives no output
Attached below is an image in which I’ve written my code in Sublime(left)
and the same code wrriten by the tutor in the right hand side
I tried referring to the code written by others here and still cannot find the real problem here

<p id="output">Default Text</p>

	<input id="user_number">

	<button onclick="update_user()">Submit</button>

    <script type="text/javascript">
    	function update_user(){
        user_number = document.getElementById("user_number").value;

    		httpRequest = new XMLHttpRequest();

    		httpRequest.open("GET", "https://reqres.in/api/users/"+user_number);

    		httpRequest.send();

    		httpRequest.onreadystatechange = function(){
    			
    			if (this.readystate == 4 && this.status == 200) {
                
                user_data = JSON.parse(this.responseText);
                
                document.getElementById("output").innerHTML = user_data.data.first_name;
    			}
    		}
    	}

    </script>

Ajax Issue|666x500

Hi @khandwawalaaliasgar9,
Please note that as in your screenshot, you have spelled readyState as readystate. Please make that change and you are good to go.
if (this.readyState == 4 && this.status == 200)
{

}

Do let me know in case you need any help.

3 Likes

Yes it works now, Thank you for your reply!!

1 Like

Hello
I am facing a problem in Ajax JavaScript .I have read all the solutions you gave and checked but I still didn’t get the output .I have attached the code .Kindly check it…

Hey @jananipraveen2002 this is the same mistake that I did.
Just change the “this.readystate” in the if statement to “this.readyState”.
And also inside the if statement make it “user_data.data.first_name”

1 Like

Thank you @khandwawalaaliasgar9 for clarifying my doubts.I didn’t noticed your code clearly,sorry for that .Now I got the output.

No issues, Glad to help!!