使用AJAX向Google圖表API發布POST

[英]Making a POST to Google chart API with AJAX


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:

我正在嘗試使用谷歌圖表API在網站上使用ajax制作一些圖表(不要重新加載頁面)。但我遇到了問題。我必須使用POST來發出請求,但我不知道ajax是否允許這樣做。例如:

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?

沒有成功,因為我認為ajax無法處理響應的類型。有人可以證實嗎?還有其他方法可以使用ajax嗎?

1 个解决方案

#1


0  

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/10/27/72119521838a698a9ee0d46dcd6b72e4.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com