2

我有这个代码

$.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',
4

4 回答 4

3

只需像这样附加变量:

url:'http://localhost/record/FlashWavRecorder-master/jjj/r/'+var,

旁注:
不要尝试使用 usevar作为变量名。这是不可能的,因为var它是一个保留关键字。
(但我确信这只是为了说明这个例子)

于 2012-12-04T07:59:40.857 回答
0

只需定义一个变量,然后将其附加到字符串中。

var someValue = "hello";
$.ajax({
 url:'http://localhost/record/FlashWavRecorder-master/jjj/r/' + someValue,
于 2012-12-04T08:00:06.487 回答
0

像这样附加到它:

   var something = "test";
   $.ajax({
                url:'http://localhost/record/FlashWavRecorder-master/jjj/r/' + something,

Javascript 不会扩展字符串中的变量,您必须将它们与+运算符连接起来。

于 2012-12-04T08:00:12.453 回答
0

尝试使用以下

url:'http://localhost/record/FlashWavRecorder-master/jjj/r/' + variable ,
于 2012-12-04T08:00:26.893 回答