我有一个javaScript脚本,如下所示:
$.ajaxFileUpload({
url: url,
secureuri: false,
fileElementId: ['upload-file'],
dataType: "JSON",
data:{ "sample_path":$(".demo-view-container-left .view img").attr("src")},
success: function (data)
{
data=JSON.parse(data);
json = JSON.stringify(data.prediction, undefined, 4)
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
var cxt_text=c.getContext("2d");
for(var i=0; i<data.prediction.length; ++i){
score_location=data.prediction[i][i.toString()]
location=score_location['location']
cxt.moveTo(location['left'], location['top']);
cxt.lineTo(location['left']+location['width'], location['top']);
cxt.lineTo(location['left']+location['width'], location['top']+location['height']);
cxt.lineTo(location['left'], location['top']+location['height']);
cxt.lineTo(location['left'], location['top']);
cxt.stroke();
cxt_text.font="12px";
cxt_text.fillText(score_location['score'].toString(), location['left'], location['top']);
}
$(".demo-view-container-right p").html("预测JSON:<br>"+json)
},
error: function (data)
{
}
它可以进入success
部分并执行所有行,但最后它会转到一个新的URL,这是当前URL附加[object%20Object]
导致404错误。如何解决这个问题呢?
谢谢。
答案 0 :(得分:1)
您正在导航,因为以下行是
location=score_location['location'] <-- that is the line that is doing it.
位置指向widow.location,所以你正在做
window.location = { ... }
当你不使用var
并且变量对窗口对象有意义时会发生这种情况。所以声明它
var location = score_location['location']