如何从php文件发送url到js文件
问题描述:
php file
<?php
function myfunc()
{
//code here
}
?>
<script>
var ur="ajaxc-alling-file.php";
</script>
<script src="custom.js"></script>
js file
jQuery(document).ready(function(){
var geturl=ur;
alert(geturl);
});
Result will be display in alert box "ajaxc-alling-file.php"
答
You cannot send url in a file but can call js function with url in arguments. for example. in file define a funcrion
//script.js
function myScriptFunction(url){
alert(url);
}
include this file in your php file and in your php file just call funcrion by passing url argument. like.
<script>
var url = "<?php echo get_url(ID);?>";
myScriptFunction(url);
</script>
答
Try this,
jQuery(document).ready(function(){
var url="ajaxc-alling-file.php";
alert(url);
});