2

I have this code

$.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> ');
   }
});

I want to add varible to this part of code

url:'http://localhost/record/FlashWavRecorder-master/jjj/r/+var',
2
  • You mean you want to add some params for the ajax request? Commented Dec 4, 2012 at 7:59
  • Do what undefined said, note though, that "var" is reserved word :) Commented Dec 4, 2012 at 8:00

4 Answers 4

3

Just append the variable like this:

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

Side-note:
Don't try to use use var as your variable name. That's not possible since var is a reserved keyword.
(But I'm sure this is just to illustrate the example)

Sign up to request clarification or add additional context in comments.

Comments

0

Just define a variable, and then append it in the string.

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

Comments

0

Append to it like:

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

Javascript doesn't expand variables within strings, you have to concatenate them with the + operator.

Comments

0

Try using the following

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.