Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我们能在邮件中找到链接吗?_Php_Codeigniter - Fatal编程技术网

Php 我们能在邮件中找到链接吗?

Php 我们能在邮件中找到链接吗?,php,codeigniter,Php,Codeigniter,我在我的网站上有一个引导导航栏,其中的下拉列表中充满了来自数据库的一些数据 现在,当我点击这个链接时,我想把数据以POST的形式发送给我的控制器。这可能吗 这是我的下拉列表: <ul class="dropdown-menu"> <li><a href="#"> <?php foreach($sites as $site) { echo "<li>".$site->site_key."</l

我在我的网站上有一个引导导航栏,其中的下拉列表中充满了来自数据库的一些数据

现在,当我点击这个链接时,我想把数据以POST的形式发送给我的控制器。这可能吗

这是我的下拉列表:

<ul class="dropdown-menu">
    <li><a href="#">
    <?php
    foreach($sites as $site) {
        echo "<li>".$site->site_key."</li>";
    }
    ?>
    </a></li>
</ul>
更新代码:

 <form id="hiddenForm" method="post"   style="display: none">
          <input name="linkAddress" value="<?php echo $site->site_key; ?>">
          <input name="otherData" value="">
    </form>


<script>
      var specialLinks = document.getElementsByClassName("specialLink");
        var hiddenForm = document.getElementById('hiddenForm');


        Array.prototype.forEach.call(specialLinks, function(link) {
        link.onclick = function(event) {
            event.preventDefault();
            var req = new XMLHttpRequest();

            req.addEventListener('load', function() {
                var response = req.responseText;

                //Do something with response, like change a part of the page
            });

            //Set the page to send the request to
            req.open('POST', 'recieve.php');
            //Specify that we're using URL-encoded coded parameters
            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            //Send the URL-encoded POST data.
            req.send('linkAddress=' + link.href + '&otherData=' + someOtherData());
        }

    </script>


您可以覆盖链接的常规行为,在单击时发送帖子,然后只提供链接的href作为参数

发送帖子最简单的方法可能是将一个隐藏表单设置为POST,然后通过编程设置表单字段,然后在有人单击链接时提交

例子 我编写了一个示例页面,使用这两种变体发送请求:

<! DOCTYPE HTML> 
<html>
    <head>
        <title>Post Send Example</title>
    </head>
    <body>
        <!-- Place somewhere on your page if you're using the hidden form method:
        The display needs to be none so the form doesn't show.
        Ideally, this won't use inline styling, obviously.-->
        <form id="hiddenForm" method="post" action="receive.php" style="display: none">
            <input name="linkAddress" value="">
            <input name="otherData" value="">
        </form>
        <!-- You could also programatically create the form using Javascript if you want -->

        <a class="specialLink" href="www.someaddress.com">A Link!</a>
        <a class="specialLink" href="www.someaddress.com/someSubPage">Another Link!</a>

        <script>
            var specialLinks = document.getElementsByClassName("specialLink");
            var hiddenForm = document.getElementById('hiddenForm');

            //If using a form, grab all links, and set the click handlers to fill
            // and submit the hidden form
            Array.prototype.forEach.call(specialLinks, function(link) {
                link.onclick = function(event) {
                    //Prevent the link from causing navigation. 
                    event.preventDefault();
                    //Grab the link and other field
                    var linkAddress = document.querySelector('#hiddenForm [name=linkAddress]');
                    var otherDataField = document.querySelector('#hiddenForm [name=otherData]');

                    //Set the form field to the link's address
                    linkAddress.value = link.href;

                    otherDataField.value = someOtherData();

                    hiddenForm.submit();
                }
            });

            //Or via AJAX, grab all links again, but create a AJAX request instead
            Array.prototype.forEach.call(specialLinks, function(link) {
            link.onclick = function(event) {
                event.preventDefault();
                var req = new XMLHttpRequest();

                req.addEventListener('load', function() {
                    var response = req.responseText;

                    //Do something with response, like change a part of the page
                });

                //Set the page to send the request to
                req.open('POST', 'recieve.php');
                //Specify that we're using URL-encoded coded parameters
                req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                //Send the URL-encoded POST data.
                req.send('linkAddress=' + link.href + '&otherData=' + someOtherData());
            }
        </script>

    </body>
</html>

发送后示例
var specialLinks=document.getElementsByClassName(“specialLink”);
var hiddenForm=document.getElementById('hiddenForm');
//如果使用表单,请获取所有链接,并设置要填充的单击处理程序
//并提交隐藏的表单
Array.prototype.forEach.call(特殊链接、函数(链接){
link.onclick=函数(事件){
//防止链接导致导航。
event.preventDefault();
//抓取链接和其他字段
var linkAddress=document.querySelector(“#hiddenForm[name=linkAddress]”);
var otherDataField=document.querySelector(“#hiddenForm[name=otherData]”);
//将表单字段设置为链接的地址
linkAddress.value=link.href;
otherDataField.value=someOtherData();
hiddenForm.submit();
}
});
//或者通过AJAX,再次获取所有链接,但创建一个AJAX请求
Array.prototype.forEach.call(特殊链接、函数(链接){
link.onclick=函数(事件){
event.preventDefault();
var req=新的XMLHttpRequest();
请求addEventListener('load',function(){
var响应=请求响应文本;
//做一些回应,比如改变页面的一部分
});
//设置要向其发送请求的页面
请求打开('POST','receive.php');
//指定我们正在使用URL编码的参数
请求setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//发送URL编码的POST数据。
请求发送('linkAddress='+link.href+'&otherData='+someOtherData());
}

请记住,我一个月前才学会如何使用表单,几天前才学会如何使用AJAX。虽然我知道这是可行的,但我不能说是最佳实践。还要注意,为了简洁起见,我在这里没有做任何错误处理。实际上,您应该检查AJAX请求的响应代码,以确保它正确通过y、

您可以覆盖链接的常规行为,而是在单击时发送帖子,然后只提供链接的href作为参数

发送帖子最简单的方法可能是将一个隐藏表单设置为POST,然后通过编程设置表单字段,然后在有人单击链接时提交

例子 我编写了一个示例页面,使用这两种变体发送请求:

<! DOCTYPE HTML> 
<html>
    <head>
        <title>Post Send Example</title>
    </head>
    <body>
        <!-- Place somewhere on your page if you're using the hidden form method:
        The display needs to be none so the form doesn't show.
        Ideally, this won't use inline styling, obviously.-->
        <form id="hiddenForm" method="post" action="receive.php" style="display: none">
            <input name="linkAddress" value="">
            <input name="otherData" value="">
        </form>
        <!-- You could also programatically create the form using Javascript if you want -->

        <a class="specialLink" href="www.someaddress.com">A Link!</a>
        <a class="specialLink" href="www.someaddress.com/someSubPage">Another Link!</a>

        <script>
            var specialLinks = document.getElementsByClassName("specialLink");
            var hiddenForm = document.getElementById('hiddenForm');

            //If using a form, grab all links, and set the click handlers to fill
            // and submit the hidden form
            Array.prototype.forEach.call(specialLinks, function(link) {
                link.onclick = function(event) {
                    //Prevent the link from causing navigation. 
                    event.preventDefault();
                    //Grab the link and other field
                    var linkAddress = document.querySelector('#hiddenForm [name=linkAddress]');
                    var otherDataField = document.querySelector('#hiddenForm [name=otherData]');

                    //Set the form field to the link's address
                    linkAddress.value = link.href;

                    otherDataField.value = someOtherData();

                    hiddenForm.submit();
                }
            });

            //Or via AJAX, grab all links again, but create a AJAX request instead
            Array.prototype.forEach.call(specialLinks, function(link) {
            link.onclick = function(event) {
                event.preventDefault();
                var req = new XMLHttpRequest();

                req.addEventListener('load', function() {
                    var response = req.responseText;

                    //Do something with response, like change a part of the page
                });

                //Set the page to send the request to
                req.open('POST', 'recieve.php');
                //Specify that we're using URL-encoded coded parameters
                req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                //Send the URL-encoded POST data.
                req.send('linkAddress=' + link.href + '&otherData=' + someOtherData());
            }
        </script>

    </body>
</html>

发送后示例
var specialLinks=document.getElementsByClassName(“specialLink”);
var hiddenForm=document.getElementById('hiddenForm');
//如果使用表单,请获取所有链接,并设置要填充的单击处理程序
//并提交隐藏的表单
Array.prototype.forEach.call(特殊链接、函数(链接){
link.onclick=函数(事件){
//防止链接导致导航。
event.preventDefault();
//抓取链接和其他字段
var linkAddress=document.querySelector(“#hiddenForm[name=linkAddress]”);
var otherDataField=document.querySelector(“#hiddenForm[name=otherData]”);
//将表单字段设置为链接的地址
linkAddress.value=link.href;
otherDataField.value=someOtherData();
hiddenForm.submit();
}
});
//或者通过AJAX,再次获取所有链接,但创建一个AJAX请求
Array.prototype.forEach.call(特殊链接、函数(链接){
link.onclick=函数(事件){
event.preventDefault();
var req=新的XMLHttpRequest();
请求addEventListener('load',function(){
var响应=请求响应文本;
//做一些回应,比如改变页面的一部分
});
//设置要向其发送请求的页面
请求打开('POST','receive.php');
//指定我们正在使用URL编码的参数
请求setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//发送URL编码的POST数据。
请求发送('linkAddress='+link.href+'&otherData='+someOtherData());
}
请记住,我一个月前才学会如何使用表单,几天前才学会以这种方式使用AJAX。虽然我知道这是可行的,但我不能谈论最佳实践。还要注意,为了简洁起见,我在这里没有做任何错误处理。实际上,您应该检查AJAX请求的响应代码以确保
<ul class="dropdown-menu">
        <a href="#" class="specialLink" id="54th-65hy">
            <li>54th-65hy</li>
          </a>

       <a href="#" class="specialLink" id="HT45-YT6T">
            <li>HT45-YT6T</li>              
          </a>
  </ul>
$( ".specialLink" ).click(function() {
      var value = this.id; //get value for throw to controller
    alert(value);  

  $.ajax({
         type: "POST", //send with post
         url: "<?php echo site_url('welcome/post) ?>", //for example of mine , using your controller
       data: "value=" + value, //assign the var here 
         success: function(msg){
            alert(msg);
         }
    });
});
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    public function index()
    {

    }

    public function post()
    {
        $value=$this->input->post('value');
    echo $value;
    }

  }
   $( ".specialLink" ).click(function() {
      var value = this.id; //get value for throw to controller
    alert(value);  

  $.ajax({
         type: "POST", //send with post
         url: "<?php echo site_url('welcome/post) ?>", //for example of mine , using your controller
       data: "value=" + value, //assign the var here 
         success: function(msg){
            alert(msg);
         }
    });
});