How to transfer php code from javascript to PHP?

删除回忆录丶 提交于 2019-12-12 03:59:00

问题


So I create text(php) editor and I want to execute PHP code without refreshing page. Now I use cookies to transfer code from javascript(which grab editor content). Then color box opens and PHP file write cookie content to file, which is included. And there is question:

Is there any other way to transfer PHP code from javascipt to PHP? Or any other way to execute PHP code? I know there is a AJAX, but I want to transfer a larger data including special characters(",',],[,$ etc.), that occur in PHP.

Yes, I use it only on localhost for education purpose only :) Sorry for my english, I hope you understand me.


回答1:


AJAX is suitable for sending large amounts of code. Take a look at jQuery.post and jQuery.ajax. Special characters pass through POST-request unchanged.

Make sure you set php setting magic_quotes_gpc to off, as this option tells PHP to escape any special character with backslash.




回答2:


You can still use AJAX, only with POST, this time. Try something like:

<script>
code = '<? echo "Hi"; ?>'
ajax = new XMLHttpRequest();
ajax.open("POST","http://foo.com/bar.php";
ajax.send("code="+code+"&foo=bar")
</script>

Look at https://developer.mozilla.org/en/ajax to learn more about Ajax.



来源:https://stackoverflow.com/questions/7010506/how-to-transfer-php-code-from-javascript-to-php

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