javascript调用php函数我在做什么错? [英] javascript calling php function what am i doing wrong?
本文介绍了javascript调用php函数我在做什么错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< html < 头部 >
< 标题 > 练习2:使用DOM测试JavaScript < /title >
< /head >
< 正文 =" " >
<? php
如果 (isset($ _ GET [action ])){
// 检索 the 获取 参数 和 执行 the
$ funcName = $ _ GET [操作];
$ funcName ();
} 其他 如果 (isset($ _ POST [action])){
// 检索 the POST 参数 和 执行 > the fu nction
$ funcName = $ _ POST [操作];
$ funcName();
} 其他 {
// 如果 有 是 否 操作 in > the URL, 然后 执行 此
回声 "< INPUT 名称 =' btnSubmitAdmin' 类型 =' 按钮' =' =' > ;
}
函数phpFunction(){
$ filename ="C:\ test01.txt"; //我们文件的名称.
$ content =报告名称"; //我们将要写入文件的内容.
$ strlength = strlen($ content); //获取$ content字符串的长度.
$ create = fopen($ filename,"w"); //使用fopen创建我们的文件.
$ write = fwrite($ create,$ content,$ strlength); //将我们的字符串写入文件.
$ close = fclose($ create); //关闭文件
回声" BR < BR > < BR > ;
}
?>
< 脚本 = 类型 =" >> ;
<!- 在非JavaScript浏览器中隐藏脚本
//SayHello()在文档的"hello"区域中打印一条消息
函数SayHello(){
var url =<?php echo $ _SERVER [PHP_SELF];?>?action = phpFunction =";
window.open(url,"_self");
//var fso = new ActiveXObject("Scripting.FileSystemObject");
//var s = fso.CreateTextFile("C:\\ Test.txt",true);
//s.WriteLine('报告名称');
//s.Close();
}
->
< /script >
< div =" hello_area" < >
< 输入 =" 按钮" 值 >点击我" onclick =" SayHello()" >
< /body >
< /html >
我在目录
解决方案
_GET [action])){{span> // 检索 the 获取 参数 和 执行 the blockquote>
funcName
_GET [action]; blockquote>
<html> <head> <title>Exercise 2: Use DOM to Test JavaScript</title> </head> <body onload=""> <?php if (isset($_GET[action])){ // Retrieve the GET parameters and executes the function $funcName = $_GET[action]; $funcName(); } else if (isset($_POST[action])){ // Retrieve the POST parameters and executes the function $funcName = $_POST[action]; $funcName(); } else { // If there is no action in the URL, then do this echo "<INPUT NAME='btnSubmitAdmin' TYPE='button' ONCLICK='javascript:SayHello()' VALUE='Call Javafunction() which redirects to a PHP function'>"; } function phpFunction(){ $filename = "C:\test01.txt"; //the name of our file. $content = "Report Name"; //what we will be writing to our file. $strlength = strlen($content); //gets the length of our $content string. $create = fopen($filename, "w"); //uses fopen to create our file. $write = fwrite($create, $content, $strlength); //writes our string to our file. $close = fclose($create); //closes our file echo "<BR>function phpFunction<BR><BR>"; } ?> <script language=javascript type="text/javascript"> <!-- Hide script from non-JavaScript browsers // SayHello() prints a message in the document's "hello" area function SayHello() { var url="<?php echo $_SERVER[PHP_SELF];?>?action=phpFunction="; window.open(url, "_self"); //var fso = new ActiveXObject("Scripting.FileSystemObject"); //var s = fso.CreateTextFile("C:\\Test.txt", true); //s.WriteLine('Report Name'); //s.Close(); } --> </script> <div id="hello_area">This text is replaced.</div> <input type="button" value="click me" onclick="SayHello()"/> </body> </html>
I am not getting any new page or any text file craeted in the directory解决方案_GET[action])){ // Retrieve the GET parameters and executes the function
funcName =
_GET[action];
这篇关于javascript调用php函数我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文