开发者

JS <---> PHP communication [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I need to, using JS get some val开发者_如何转开发ues returned by a PHP script.

How to achieve that?


<script type="text/javascript">
var string = <?php echo $variable; ?>;
</script>

or AJAX


AJAX: http://www.devirtuoso.com/2009/07/beginners-guide-to-using-ajax-with-jquery/


You can create a js file with PHP.

For exemple

// My script php
var js_var = '<?php echo "toto"?>';

or use an AJAX framework and JSON


What's the method you're using to communicate with PHP? If you're using AJAX you might want to checkout jQuery or a library of some sort and use JSON for communication.

Using these methods, like using getJSON, you can easily access the variables returned by the PHP-script.

Please provide some more details to your question so we can answer your question in more detail and provide some examples.


You can assign php values to JavaScript like so:

var x = <?php echo $varible ; ?>;


In JavaScript, you can use a XMLHttpRequest to access your PHP script. This is called AJAX. I recommend you the JSON serialization method for the data you send & receive to / from the PHP script.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜