如何将变量从javascript发送到PHP [英] How to send variables from javascript to PHP

查看:95
本文介绍了如何将变量从javascript发送到PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将变量从javascript发送到php,这样我就可以创建一个包含动态行总和的变量。

I want to know how to send variables from javascript to php so i can create a variable that contains dynamic sum of rows.

更具体:
当我在搜索框中搜索时,我想获得行数(1个匹配是1行,2个匹配是2行,依此类推)

More specific: When I search in my search box, i want to get the number of rows (1 match is 1 row, 2 matches is 2 rows and so on

我试图实现这个:document.getElementById(i1)。value = allCells.length;所以后来我可以在php中调用,但是我没有工作。

I tried to implement this: document.getElementById("i1").value = allCells.length; so i later could call in the php, but i did not work.

这是我的javascript,顺便说一句javascript工作正常。

This is my javascript, by the way the javascript works perfectly.

<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
<script language="javascript" type="text/javascript">  
  $(document).ready(function() 
  {
    $('#search').keyup(function() {
      searchTable($(this).val());
    });
  });
  function searchTable(inputVal) 
  {
    var table = $('.table');
    table.find('tr').each(function(index, row) 
    {
      var allCells = $(row).find('td');
      if (allCells.length > 0) {
        var found = false;
        allCells.each(function(index, td) 
        {
          var regExp = new RegExp(inputVal, 'i');
          if (regExp.test($(td).text())) 
          {
            found = true;
            return false;
            document.getElementById("i1").value = allCells.length;
          }
        });
        if (found == true)
          $(row).show();
        else
          $(row).hide();
      }
    });
  }

  $(function()
  {
    $('#table a').click(function(e) 
    {
      e.preventDefault();
      $('#result').val($(this).closest('tr').find('td:first').text());
    });
  });
</script>

我想在表格标题中吐出她动态的行数。

I wanted to spit the dynamicelly sum of rows her in my table header.

 <h3>Total: (<?php print_r($_GET["i1"])?>)  </h3>

我希望你能帮助我。

推荐答案

你可能从来没有学过javascript和php之间的区别

You probably have never learned the difference between javascript and php

Javascript是客户端的,这意味着一切都由你的本地系统处理。 PHP是服务器端,这意味着服务器处理所有内容并解析为html。

Javascript is clientsided, which means everything is processed by your local system. PHP is server sided which means everything is processed by the server and parsed into html.

你不能像你一样从javascript发送一个值到普通的PHP。
然而,您可以发送帖子或获取相同的脚本并让它重新加载脚本的一部分

You can't send a value from javascript into plain php like you did. You can however send a post or get to the same script and let that reload a part of your script

http://api.jquery.com/jQuery.get/

< a href =http://api.jquery.com/jQuery.post/ =nofollow> http://api.jquery.com/jQuery.post/

这篇关于如何将变量从javascript发送到PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆