0

Following piece of code works in my localhost, but when i upload files in my server behaves very strange.

$(function(){
var myPath=<?= BASE_URL ?>+'myaddress/mystatelist';
$('#country').val('US')
loadMystate('US',myPath);
});

Actually I created vhost in my localhost like "test.study.com/projectname" which means "<?= BASE_URL ?>" will takes "/projectname" as a BASE_URL. Facing issue when i upload files under the BASE_URL "http://dev.study.com". Now i am getting error in firebug as "missing ; before statement var myPath=http://dev.study.com/+'myaddress/mystatelist'; "

What I done wrong this code? Kindly help me.

mymotherland
  • 7,968
  • 14
  • 65
  • 122
  • What does the actual generated javascript code look like after PHP has processed it? – jfriend00 Aug 08 '11 at 05:37
  • If you don't understand why some JS isn't working — show us the **JavaScript**. Don't show us some PHP that will generate some JS when it is executed. – Quentin Aug 08 '11 at 05:37
  • It'd be a pretty crappy mechanic who wouldn't work on your car because you thought something was wrong with the differential when the problem was really with the suspension. – mVChr Aug 08 '11 at 06:13

5 Answers5

1

You're missing quotes around the base URL so it's trying to interpret it as code. Try:

var myPath = '<?= BASE_URL ?>myaddress/mystatelist';
mVChr
  • 49,587
  • 11
  • 107
  • 104
1

Your JS code looks like this :

var myPath=http://dev.study.com/+'myaddress/mystatelist';

Your are missing quotes arround the first string :

var myPath='http://dev.study.com/'+'myaddress/mystatelist';

And, to get those quotes generated from PHP, your PHP code should probably look like this :

var myPath = '<?= BASE_URL ?>' + 'myaddress/mystatelist';


Or your could remove the strings concatenation, and directly use :

var myPath = '<?= BASE_URL ?>myaddress/mystatelist';
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
0

Strings have to be quoted in JavaScript.

var myPath=http://dev.study.com/

Where are the quotes?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

var myPath='<?= BASE_URL ?>myaddress/mystatelist';

Your PHP code is written to the output, but it was not inside a string. Your value would have thrown an invalid RegEx error in JS.

Also, $('#country').val('US') - are you sure that's doing anything and it does appear to be missing a ;.

AndrewR
  • 6,668
  • 1
  • 24
  • 38
0

Also, the short tag <?= may not be supported on your server. There's a good answer about this at Are PHP short tags acceptable to use?.

On second thought, that's probably not the issue as the variable is printing - sorry!

Community
  • 1
  • 1
g_thom
  • 2,810
  • 2
  • 18
  • 18