问题描述
- 怎么样通过ajax把参数传递给上级目录 的php文件?
-
目录结构如下:www/a/b/c;
html文件在c目录下,要在这个html文件中通过jquery的ajax方式把act=remove&id=2
传给b目录下的一个php文件,
可以这么做吗?
如果可以
jquery中的ajax函数要怎么写? 具体的就是那个url参数该怎么写?
html文件代码:<html> <head> <script type="text/javascript" src="jquery-1.11.2.js"></script> </head> <body> PHONE:<input type="text" name="phone" id="phone" ></input> ORDER:<input type="text" name="order" id="order" ></input> ZIP:<input type="text" name="zip" id="zip" ></input> <input type="submit" name="submit" value="submit" onclick="dd()" /> </body> <script language="javascript" type="text/javascript"> function dd(){ $.ajax({ url:"../2.php", type:"GET", data:{ phone:$("#phone").val(), zip:$("#zip").val() }, success:function(data){ alert(data); } } ); } </script> </html
php代码:
<?php print_r($_GET);
php文件在根目录下,html文件在根目录下的一个文件夹里
解决方案
可以啊。。。
$.ajax({url:'../xxxxx.php',data:'act=remove&id=2',type:'POST'});
../就是返回上一级目录,在加一个就返回到a目录(../../xxx.php)
解决方案二:
这个很简单的,返回上一级目录的一个文件:../x.php,返回上上级目录的就是../../x.php
当然你也可以直接是使用url地址,比如http://www.abc.com/a/b/x.php或者http://www.abc.com/a/x.php等方式的
解决方案三:
和时不时上一级目录没有关系,只要你有url直接用querystring就能传了。既可以post也可以get。
时间: 2024-08-03 22:59:03