How add var to text javascript

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',

Answers:

Answer

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)

Answer

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

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

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.

Answer

Try using the following

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.