Jonathon Powell Jonathon Powell - 4 months ago 6x
HTML Question

This Javascript function wont run properly

In html code, when an input button is clicked, this function would be called. Nothing is happening so I assume that there is an error with the code. Removing the block internals and keeping the 1st line of the block, "boi..." is successfully the new html code. With the rest of the code applied, nothing happens. What am I doing wrong and how can I fix this?

function uploadPost(){
document.getElementById("status").innerHTML = "boi....";
var hr = new XMLHttpRequest();
var url = "send_post.php";
var fn = document.getElementById("post").value;
var vars = "post=" + fn;"POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function(){
if(hr.readyState == 4 $$ hr.status == 200){
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
document.getElementById("status").innerHTML = "processing...";


Your if statement has a typo. Change your operators from $$ to &&.

You will have to replace this line:

if(hr.readyState == 4 $$ hr.status == 200){

With this:

if(hr.readyState == 4 && hr.status == 200){