开发者

passing a string variable from php to a JS function

I was looking for a way to pass a string(variable saved in a form of $x) from php to Java Script and I found so many codes to solve that, but my question is : does those strings have to be declared global?!

i did dec开发者_如何学编程lare it as a global variable but still no response ..!

any other suggestions?!

Pass a PHP string to a JavaScript variable (and escape newlines)

I tried most of these codes, none of them worked,


As the others have said, all we can say is that you are doing something wrong. You can place PHP variable values, strings or otherwise, wherever you want in your JavaScript code, since PHP is server-side and can do whatever you like on the client side.


This will help you to solved the issue of passing string variable value by calling the javascript function within php scrpt. :)

<?php

$testStrFileName = "test.jpg";

$file_name = "<script>". $testStrFileName ."</script>";

//<sample tags/>

echo '<a href="javascript:deleteGalleryImage('.$file_name.');">Delete</a>';

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜