FCC数据暂存

  1. random quote

    Random Quote




    "说什么呢"

    ——张大侠








js部分

var ajaxRequest ;
function createRequest(){
var request
try {
request = new XMLHttpRequest();
} catch(tryMS) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch(otherMS) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
console.log("失败");
return null;
}
}
}
return request;
}

function stateChange(request) {
if (ajaxRequest.readyState === 4) {
if (ajaxRequest.status === 200) {
var r = JSON.parse(ajaxRequest.responseText);
var quote = r.quote;
var author = r.author;
$(".disp-text").html = quote;
}
else {
alert("错误");
}
}
}
function stateChange() {
if (ajaxRequest.readyState === 4) {
if (ajaxRequest.status === 200) {
var r = JSON.parse(ajaxRequest.responseText);
var quote = r.quote;
var author = r.author;
$("p").html(quote);
console.log(quote);
}
else {
alert("错误");
}
}
}

$(document).ready(function(){
$("#get-info").on("click", function(){
ajaxRequest = new XMLHttpRequest();
var url = "https://andruxnet-random-famous-quotes.p.mashape.com/cat=";

    ajaxRequest.open("GET", url, true);
    ajaxRequest.setRequestHeader( "X-Mashape-Key", "OivH71yd3tmshl9YKzFH7BTzBVRQp1RaKLajsnafgL2aPsfP9V");
    ajaxRequest.setRequestHeader("Accept", "application/json");
    ajaxRequest.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded");

    ajaxRequest.onreadystatechange = stateChange;
    ajaxRequest.send(null);
});

});

你可能感兴趣的:(FCC数据暂存)