我正在尝试在要在 Ajax 请求中使用的 URL 中添加一个变量(整数):
在我的 HTML 中,我有:
<span class="user">15</span>
和脚本:
$('#fileupload').click(function () {
$(this).fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
if (file.error != null) {
$console.text(file.error);
}
var user = parseInt($(".user").text(), 10);
//Open the uploaded file//
$.ajax({
url: "files/" + user + '/' + file.name,
dataType: 'json',
type: 'GET',
success: function (res) {
handsontable.loadData(res.data);
$console.text('Loaded file: ' + file.name);
}
});
});
}
});
});
但是,变量 (15) 没有传递给 URL,我收到错误:
/files/NaN/data.json
我知道我在做一些愚蠢的事情,并且到处搜索,但它是什么?