$.ajax({
type: "GET",
url: "http://api.zip-tax.com/request/v20",
data: {
key: '1234567890',
postalcode: '90265',
format: 'json'
},
success: function (json) {
debugger;
// do stuff with json (in this case an array)
alert("Success");
},
error: function (a, b, c) {
debugger;
alert("Error");
}
});
當我上面的代碼運行時,它拋出我的錯誤塊,並說跨域獲取Ajax請求拋出分析錯誤
SyntaxError: invalid label
[Break On This Error]
{"version":"v20","rCode":100,"results":[{"geoPostalCode":"902
雖然它也表明readyState=4, status=200, statusText="success"
和parsererror
如果我打的網址,我可以看到正確的json
URL: `http://api.zip-tax.com/request/v20?key=1234567890&postalcode=90265&format=json`
Result: `{"version":"v20","rCode":100,"results":[{"geoPostalCode":"90265","geoCity":"MALIBU","geoCounty":"LOS ANGELES","geoState":"CA","taxSales":0.090000003576279,"taxUse":0.090000003576279,"txbService":"N","txbFreight":"N","stateSalesTax":0.064999997615814,"stateUseTax":0.064999997615814,"citySalesTax":0,"cityUseTax":0,"cityTaxCode":"","countySalesTax":0.0099999997764826,"countyUseTax":0.0099999997764826,"countyTaxCode":"19","districtSalesTax":0.014999999664724,"districtUseTax":0.014999999664724},{"geoPostalCode":"90265","geoCity":"PT DUME","geoCounty":"LOS ANGELES","geoState":"CA","taxSales":0.090000003576279,"taxUse":0.090000003576279,"txbService":"N","txbFreight":"N","stateSalesTax":0.064999997615814,"stateUseTax":0.064999997615814,"citySalesTax":0,"cityUseTax":0,"cityTaxCode":"","countySalesTax":0.0099999997764826,"countyUseTax":0.0099999997764826,"countyTaxCode":"19","districtSalesTax":0.014999999664724,"districtUseTax":0.014999999664724},{"geoPostalCode":"90265","geoCity":"TWAIN HARTE","geoCounty":"VENTURA","geoState":"CA","taxSales":0.075000002980232,"taxUse":0.075000002980232,"txbService":"N","txbFreight":"N","stateSalesTax":0.064999997615814,"stateUseTax":0.064999997615814,"citySalesTax":0,"cityUseTax":0,"cityTaxCode":"","countySalesTax":0.0099999997764826,"countyUseTax":0.0099999997764826,"countyTaxCode":"56","districtSalesTax":0,"districtUseTax":0}]}`
請指教。我不'想寫一個服務器端腳本。
該內容不是JSONP。這是常規的JSON。 – 2013-04-25 06:57:52
okie,如何撥打正確的電話?我嘗試沒有jsonp也沒有工作。 – 2013-04-25 07:02:23