sending an url but staying on the same page ( php, codeigniter, javascript )

浪子不回头ぞ 提交于 2019-12-24 02:16:18

问题


this is my situation. I'm writing an webinterface in codeigniter to send commands to a virtual server. these commands are passed through the browser in an url.

example : http://server.com/TgtSendIRCommand?id=UM-02&code=KEY_UP this server then takes action and the web interface refreshes the screenshot.

i just want to have a bunch of links in html that send this command to the browser. But if i click the links, the user has to stay on the same page. So the command is sended but there is no other interaction.

i am using codeigniter.

Any suggestions ?


回答1:


Make a view and copy this in your view:

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script>
</head>
<body>
<a href="#" id="myBtn">Click here!</a>

<script type="text/javascript">
  $(document).ready(function(){
     $("#myBtn").click(function(){  
       $.get("http://server.com/TgtSendIRCommand?id=UM-02&code=KEY_UP ");        
     });
  });
</script>
</body>
</html>

Not tested but something as above should do the trick for you.




回答2:


<?php
        session_start();
        $_SESSION['http://localhost/profile.php'] = $_SERVER['REQUEST_URI'];
        $sess=$_SESSION["email"];
        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname ="reg";
        if(!isset ($sess)) 
        { 
            header("Location:login.php");
            exit;
        }


来源:https://stackoverflow.com/questions/13085388/sending-an-url-but-staying-on-the-same-page-php-codeigniter-javascript

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