/    Sign up×
Community /Pin to ProfileBookmark

passing PHP var into JS function in included .js file?

This seems like such a simple thing but it has me stuck.
I have a function inside a function in a .js file that gets included in a PHP page. I simply need to pass it a PHP var and I keep getting various errors (usually syntax) no matter how I try.

Here’s the pertinent content of the .js file:

[CODE]$(document).ready(function() {
[… cut code …]
$(“#country_id”).change(function zoneData(countryID, zoneID, name, zoneName) {
$.ajax({
url: ‘<?php echo base_url(); ?>’ + countryID + ‘/’ + zoneID + ‘/’ + name + ‘/six/’ + zoneName,
type: ‘POST’,
success: function(data) {
$(‘#zone_name’).html(data);
}
});
});
});[/CODE]

Note the base_url() in the url section. That’s what I need filled.
I’ve tried that, I’ve tried putting it in the function arguements and replacing it with a var. I’ve tried json_encode as a var and passing that to the function. Looking at the console and the HTML source, nothing I do generates the actual base_url value, it ALWAYS displays the literal <?php…?> script, regardless of quotes or escaping….

Any suggestions? ?

Thanks for any help!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @mechphisto spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...