我有下面的ajax调用,在这里我以JSON格式传递数据,当执行这段代码时,我得到如下所示的错误,我在下面显示了Console.log(data-cp),并在http://jsonlint.com/中验证了它,这是一个验证过的输入?我错过了什么?如何修复此错误?我看了其他的帖子,比如json parsing error syntax error unexpected end of input,但是我想不出。。。
$.ajax({
dataType: "json",
type: "POST",
contentType: "application/json",//note the contentType defintion
url: "scripts/cherrypick.py",
data: JSON.stringify(data_cp),
//data: data_cp,
error : function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
},
success: function(message){
console.log("cherypick sucess");
}
服务器端python脚本:
#!/usr/bin/python
import os
import sys
import json
print "Content-type: application/json\n\n"
...............
...............
def main():
result = {'success':'true','message':'The Command Completed Successfully'}
cherrypicklist = []
cherrypickfaillist = []
myjson = json.load(sys.stdin)
gerritlist = myjson['gerrits']
resource = r'buildserver'
buildlocation = r'cd /local/mnt/workspace/user/buildlocation ; '
for gerrit in gerritlist:
cmd = buildlocation
project,ref = fetchgerritproject(gerrit, connection=None)
proj_path = getprojectpath(project)
cmd += 'cd ' + proj_path + ' ;'
new_cmd = ' gknife am-or-cp ' + gerrit
pick_cmd = cmd + new_cmd
errorlist =''
errorlist = cherrypick(resource,pick_cmd)
if len(errorlist) <= 2:
cherrypicklist.append(gerrit)
else:
chk_cmd = cmd + ' git checkout -f'
connection = ssh_connect(resource)
errorlist = execute_command(connection,chk_cmd)
cherrypickfaillist.append(gerrit)
for gerrit in cherrypicklist:
cmd = buildlocation
project,ref = fetchgerritproject(gerrit, connection=None)
proj_path = getprojectpath(project)
cmd += ' cd ' + proj_path + ' ;'
errorlist = resetgerrit(resource,cmd)
errorlist = execute_command(connection,chk_cmd)
print json.dumps(result)
#return
if __name__ == "__main__":
main()
错误:
SyntaxError: Unexpected end of input
控制台.log(data_cp)输出:
{"gerrits":["1258565","1279604"]}
根据Jquery文档中错误方法的定义,如果调用不成功,则从服务器端获取错误。
所以这意味着你从服务器得到了错误。检查服务器代码。
从JQuery定义错误方法
相关问题 更多 >
编程相关推荐