如何使用JavaScript调用php函数并传递参数 [英] how to use JavaScript to call a php function and pass an argument

查看:75
本文介绍了如何使用JavaScript调用php函数并传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Javascript来调用PHP函数,例如:
我遇到的问题是参数 id 没有被传递.
函数MODIFICA($ num)在同一php文件中定义,并使用"print"返回数据(此部分有效)

I need a Javascript to call a PHP function , like that :
The problem i encounter is that the parameter id does not get passed .
Function MODIFICA($num) is defined in the same php file , and returns data using "print" ( this part works)

<p id="php_code"> Nothing yet.</p>


function JSModify(id)
 {
document.getElementById("php_code").innerHTML="<?php MODIFICA("" + id + "");/???>";
return;
 }


问题:

推荐答案

num)在同一php文件中定义,并使用"print"返回数据(此部分有效)

num) is defined in the same php file , and returns data using "print" ( this part works)

<p id="php_code"> Nothing yet.</p>


function JSModify(id)
 {
document.getElementById("php_code").innerHTML="<?php MODIFICA("" + id + "");/???>";
return;
 }


问题:


您不能直接使用Java脚本调用PHP. Javascript发生在浏览器中,PHP发生在服务器上,因此到Javascript调用页面时,该服务已被提供.

如果您确实需要从Javascript调用PHP函数,则可以使用AJAX向服务器发出另一个请求.
You can''t call PHP directly using Javascript. Javascript happens in the browser and PHP happens on the server, so by the time the Javascript is called the page has already been served.

If you really need to call PHP functions from Javascript you can use AJAX to make another request to the server.


哦,所以这就是我总是得到函数MODIFICA(0)的原因.而不是我的ID ... tnx寻求帮助.
oh , so that''s why i always get the function MODIFICA(0) instead of my id ... tnx for help .


这篇关于如何使用JavaScript调用php函数并传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆