我要開發Chrome擴展的要求,因爲我需要發佈使用REST API服務的產品信息,下面是URLjQuery的REST API後調用
https://ABCD.com/api/products/?token=XXXXf&product[name]=Headphones&product[price]=100&product[permalink]=headphones1
得到響應時,直接將在瀏覽器..
,但我需要通過JQuery AJAX調用後發佈這個..我嘗試了一些辦法,但沒有運氣..
我嘗試:
var product = [{ "name": "128.3657142857143", "price": "7", "permalink": "headphones1"}];
$.ajax({
type: "POST",
url: "URL",
// The key needs to match your method's input parameter (case-sensitive).
data: JSON.stringify({ token: 'XXXX', product: product }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) { alert(data); },
failure: function (errMsg) {
alert(errMsg);
}
});
POST調用
變種產物= [{ 「名稱」: 「128.3657142857143」, 「價格」: 「7」, 「永久」: 「headphones1」}];
$.post("URL", JSON.stringify({ token: 'XXXX', product: product }),
function (data) {
alert('success');
}
);
錯誤 的XMLHttpRequest無法加載URL。 Access-Control-Allow-Origin不允許Origin null。
好心幫我在如何形成的jquery ajax調用
請告訴我們你到目前爲止做了些什麼。 –
再次編輯該問題..再次重溫問題 –
檢查我的答案。 –