Ajax 如何在firefox扩展中创建JSON post请求?
我试图调用GoogleAPI,这是一个来自Firefox扩展的JSON post请求Ajax 如何在firefox扩展中创建JSON post请求?,ajax,json,firefox,firefox-addon,google-api,Ajax,Json,Firefox,Firefox Addon,Google Api,我试图调用GoogleAPI,这是一个来自Firefox扩展的JSON post请求 POST https://www.googleapis.com/urlshortener/v1/url Content-Type: application/json {"longUrl": "http://www.google.com/"} 如何调用此API并在Firefox扩展中处理响应?最简单的方法是使用XMLHttpRequest,就像您在网页上所做的那样(只是网页受同源策略的限制) 要序列化和解析J
POST https://www.googleapis.com/urlshortener/v1/url
Content-Type: application/json
{"longUrl": "http://www.google.com/"}
如何调用此API并在Firefox扩展中处理响应?最简单的方法是使用XMLHttpRequest,就像您在网页上所做的那样(只是网页受同源策略的限制) 要序列化和解析JSON,请参阅
var request = new XMLHttpRequest();
request.open("POST", "https://www.googleapis.com/urlshortener/v1/url");
request.setRequestHeader("Content-Type", "application/json");
request.overrideMimeType("text/plain");
request.onload = function()
{
alert("Response received: " + request.responseText);
};
request.send('{"longUrl": "http://www.google.com/"}');