我有这段代码
$.ajax({
url: 'http://localhost/record/FlashWavRecorder-master/jjj/r/',
type: 'HEAD',
error: function () {
$('.sd').html('<img src="5-0.gif" />');
},
success: function () {
bo = 'a';
$('.sd').html('<span style="color:#99CC00; font-weight:bold;">done</span> ');
}
});
我想在代码的这一部分添加变量
url:'http://localhost/record/FlashWavRecorder-master/jjj/r/+var',
答案 0 :(得分:3)
只需附加如下变量:
url:'http://localhost/record/FlashWavRecorder-master/jjj/r/'+var,
边注:
不要尝试使用var
作为变量名。这是不可能的,因为var
是保留关键字
(但我确定这只是为了说明这个例子)
答案 1 :(得分:0)
只需定义一个变量,然后将其附加到字符串中。
var someValue = "hello";
$.ajax({
url:'http://localhost/record/FlashWavRecorder-master/jjj/r/' + someValue,
答案 2 :(得分:0)
附加如下:
var something = "test";
$.ajax({
url:'http://localhost/record/FlashWavRecorder-master/jjj/r/' + something,
Javascript不会在字符串中扩展变量,您必须将它们与+
运算符连接起来。
答案 3 :(得分:0)
尝试使用以下
url:'http://localhost/record/FlashWavRecorder-master/jjj/r/' + variable ,