views:

17

answers:

1

HI all,

i'm trying to use google chart API to make some charts in a website using ajax (don't what to reload the page). But i'm having a problem. I have to use POST to make the requests but i don't known if ajax allow this. For example:

var xmlhttp=new XMLHttpRequest();

xmlhttp.open("POST","http://chart.apis.google.com/chart?",true);
xmlhttp.setRequestHeader("Content-type","image/png");
xmlhttp.send("cht=p3&chs=250x100&chd=t:60,40&chl=Hello|World");

xmlhttp.onreadystatechange=function() {

    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("div").innerHTML=xmlhttp.responseText;
    }
}

Haven't succeed, because i think ajax can't handle the type of response. Anyone can confirm that? There is any other way of doing this using ajax?

A: 

This way it will work:

var xmlhttp=new XMLHttpRequest();

xmlhttp.open("POST","http://chart.apis.google.com/chart?cht=p3&chs=250x100&chd=t:60,40&chl=Hello|World",true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = checkData;
function checkData() {
    if (xmlhttp.readyState == 4) {
             alert(xmlhttp.responseText);
    }
}
miguelpais