从3天开始,我正在努力从Ajax&
PHP,我尝试了所有教程,但我无法得到解决方案,我是Ajax,Jquery的新手,但我的问题对你们来说都很简单.
我使用jquery& amp; PHP,我已经使用HTML(ul,li)创建菜单所以我想要的是,如果我点击菜单项ajax应该发送值到PHP变量然后执行PHP函数,但所有这一切应该发生在同一页面,..
请帮我解决问题.
到目前为止,我尝试过以下方法:
<script type="text/javascript"> $("#btn").click(function() { var val = "Hi"; $.ajax ({ url: "oldindex.PHP",data: val,success: function() { alert("Hi,testing"); } }); }); </script>
PHP和HTML:
<input type="submit" id="btn" value="submit"> <form name="numbers" id="numbers"> <input type="text" name="number" id="number"> </form> <div id="number_filters"> <a href="abc">1</a> <a href="def">2</a> <a href="ghi">3</a> </div>
index.PHP页面
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#btn").click(function() { var val = "Hi"; $.ajax ({ url: "ajax.PHP",data: { val : val },success: function( result ) { alert("Hi,testing"); alert( result ); } }); }); }); </script> <input type="submit" id="btn" value="submit"> <form name="numbers" id="numbers"> <input type="text" name="number" id="number"> </form> <div id="number_filters"> <a href="abc">1</a> <a href="def">2</a> <a href="ghi">3</a> </div>
<?PHP echo ( $_GET['val'] );