问题
I want to concatenate a value inside function in jquery. See code below. I want to put value data 1 into a function. Do you have any way to achieve what I want? Appreciate.
var data='1';
var user='<?php echo bp_core_get_user_domain('+ data +');?>';
$("#find_members").html(user);
回答1:
Make an empty php page.
file.php
Inside put the PHP you want to interact with the JS value.
<?php
function bp_core_get_user_domain($something) {
//do Stuff here
return $something;
}
echo bp_core_get_user_domain($_POST['data_var']);
?>
Then on your page make an ajax request to this script and the data will come back...
var data='1';
$.post( "file.php", { data_var: data})
.done(function( data ) {
$("#find_members").html(data);
});
This is a rough version (untested), there are MANY examples out there for this.
来源:https://stackoverflow.com/questions/28666973/how-can-i-concatenate-a-value-inside-function-in-jquery-in-this-situation