I'm not sure if a PHP string can be run inside a JavaScript function. For instance:
<script language=javascript> var int=self.setInterval("message()",1000); function message() { <?PHP mysql_query("SELECT * FROM example"); ?> } </script>
I have not tried to run this, but I do not think you can run PHP like this. Can anyone help. Can I run a PHP script inside a javascript function in some way without using an external PHP file call through Ajax?
Tell us about the basics :)
PHP - , -. -, , PHP , . , : -.
Javascript - , -. , , . Javascript - -: .
, Javascript , Javascript HTTP- . , AJAX. PHP - , PHP script Javascript, , PHP json_encode, - jQuery $.getJSON .
json_encode
$.getJSON
, , . , , , ... !
. - PHP, PHP HTML-, JavaScript JavaScript. , JavaScript.
JavaScript = .
PHP = .
- , JavaScript .
, message , JavaScript eval() .
message
eval()
- php. , . php javascript templating, ajax.
I would use the jQuerys.ajax () function on the javascript side and echo json_encode($result_array)on the php side.
echo json_encode($result_array)
Source: https://habr.com/ru/post/1769655/More articles:Serialization of C-style structures (using C ++) - c ++Programmatically retrieve hard drive information on OS X - cCascaded delete SQL output - sqlWhat is the difference between these two LINQ queries? - c #Background Image Flickers on WebKit-based browsers (Safari / Chrome) - jqueryHow to set a Google search box with an offer in MediaWiki? - phpHow does an Android app load a keyboard? - androidGetting field type in method in eclipse - javaBarrier implementation in Java - javaСписок для строки [] - c#All Articles