Nida
Nida

Reputation: 1702

How to concatenate variables in jquery

var f="http://";
var s=$_SERVER['HTTP_HOST'];
var t="/wordpress/wp-content/themes/twentythirteen/getmore.php";
var last=f+s+t;
    $.ajax({
    type : "POST",
    url  : last
    ...
    ....
   });

Its not working... please help me!!!

Upvotes: 0

Views: 6516

Answers (6)

Nida
Nida

Reputation: 1702

I finally resolved it myself and the right answer is

var f="http://";
var s= location.host;
var t="/wordpress/wp-content/themes/twentythirteen/getmore.php";
var lastres=f+s+t;

Thanks evedybody for supporting me!!!

Upvotes: 0

rams0610
rams0610

Reputation: 1051

use php code to get the server name

var s = "<?php echo $_SERVER['HTTP_HOST']; ?>";

Upvotes: 0

Dipesh Parmar
Dipesh Parmar

Reputation: 27384

You also have syntax error for var s;

correct syntax is as below,

var s="<? echo $_SERVER['HTTP_HOST']; ?>";

Upvotes: 0

Hendyanto
Hendyanto

Reputation: 335

use PHP tags arount your PHP code

var f="http://";
var s="<?php echo $_SERVER['HTTP_HOST']; ?>";
var t="/wordpress/wp-content/themes/twentythirteen/getmore.php";
var final=f+s+t;
$.ajax({
type : "POST",
url  : final
...
....
});

And you might as well change the "final" to other word.

Upvotes: 0

웃웃웃웃웃
웃웃웃웃웃

Reputation: 11984

You need to quote your $_SERVER variable like this.Also final is a reserved keyword.use something else.

var s= '<?php echo $_SERVER["HTTP_HOST"] ?>';

Upvotes: 1

final is reserved word you can't use it as variable

var final1=f+s+t;

and

var s="<?php echo $_SERVER['HTTP_HOST']; ?>";

as $_SERVER['HTTP_HOST']; is php code

Upvotes: 4

Related Questions