Bri*_* Li 2 javascript python google-app-engine angularjs
我创建一个表单,当我单击提交按钮时,我将3值分配到一个javascript dict并将其发送到python脚本进行处理但是我的Web浏览器告诉我一个错误!
来自Json错误:{u'food':90,u'cargo':70,u'fuel':50} SyntaxError
controller.js
function customiseCtrl($xhr){
var self = this;
checkPoint();
this.process = function(){
if (checkPoint()){
var newPlayer = {"fuel":value, "food":value2, "cargo":value3 };
$xhr('POST', '/process', newPlayer, function (code, response) {
self.x = response;
});
}
};
}
Run Code Online (Sandbox Code Playgroud)
/ process - > python script(我正在尝试阅读"info"的信息并将其写入Google应用引擎.
def post(self):
user = users.get_current_user()
player = Player();
info = json.loads(self.request.body)
player.fuel = info.fuel
self.response.out.write(info)
Run Code Online (Sandbox Code Playgroud)
在许多情况下,打印Python dict不会生成有效的JSON.你想要的json
模块:
import json
# ... snip ...
self.response.out.write(json.dumps(info))
# or
json.dump(info, self.response.out)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2500 次 |
最近记录: |