这是我的实现,
full_url = url + '?' + params
req = urllib2.Request(full_url, params)
req.add_header('Content-Type', 'application/javascript')
req.add_header('Access-Control-Allow-Origin','*')
req.add_header('Accept', 'application/javascript')
req.add_header('x-lang', 'en')
req.add_header('x-app-version', '1.2.3')
req.add_header('x-consumer-key', 'abc')
req.add_header('x-source', 'web')
req.add_header('x-device-id', 'abc-2501015753736970469271537365900144030')
req.add_header('x-signature', signature)
req.add_header('X-Content-Type-Options', 'nosniff')
req.add_header('x-request-id', request)
req.add_header('x-timestamp', timeStamp)
response = urllib2.urlopen(req)
result = response.read()
result = result.decode('latin-1')
respjson = json.loads(result)
return respjson
读取ext.js 中的输出
var script = document.createElement("script");
script.setAttribute("src", url);
script.setAttribute("type", "text/javascript");
script.setAttribute("id", trans.scriptId);
document.getElementsByTagName("head")[0].appendChild(script);
提前谢谢。
浏览器中显示错误";即使其MIME类型("application/json"(不是有效的JavaScriptMIME";
【浏览器错误】[1]
简短回答:在ExtJS中使用JSONP而不是JSON。
附加信息吨
从ExtJS检索JSON的更好方法
但我认为这不是问题所在。
假设您有JSON,并且正在尝试填充一个存储。
您可以使用:而不是将JSON注入DOM
Ext.StoreManager.get('storeId').load(JSON);
// or for the store of a grid
Ext.ComponentQuery.query('grid')[0].getStore().load(JSON);
// or for xtype main
Ext.first('main').getViewModel().set('initData', JSON);
所有这些方法都会将数据放入ExtJS应用程序
检索数据
将数据导入ExtJS通常会使用完成
Ext.Ajax.request({
url: full_url,
header: ...
success: success_fn,
scope: this
})
或者直接在您的模型/商店中