How can I concatenate a value inside function in jquery in this situation?

断了今生、忘了曾经 提交于 2019-12-24 14:13:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!