【问题标题】:Get input field through javascript and use variable in php?通过javascript获取输入字段并在php中使用变量?
【发布时间】:2017-04-18 03:15:46
【问题描述】:

问题说明了一切。 有什么想法吗?

【问题讨论】:

  • 显示一些代码。至少是 JS 和 HTML 部分,以便可以查明可能出现的问题。
  • 很难知道没有看到有问题的 html 和 javascript。您可能在 usename 字段上没有 name 属性吗?或者,也许您可​​以使用诸如 ?username=Joe 之类的 get 参数调用 php 文件。如果不看代码,几乎不可能提供帮助。
  • 您可以尝试以下方式将参数从 UI 发送到 JS 并将其发布到 PHP。如果您显示您的代码,我们可以提供更好的帮助。

标签: javascript php input submit


【解决方案1】:

HTML

<input type="text"  name="username" class="form-control search-query" placeholder="Enter User Name">

JavaScript

$http({
            method: 'POST',
            url: 'url.php',
            //headers : {'Content-Type':'application/x-www-form-urlencoded'},
            data: {
                "username": $scope.username,

            },
        }).then(function (response) {
            var data = response.data;

        }

PHP

$postdata      = file_get_contents("php://input");
$request       = json_decode($postdata);
$accountnumber = $request->accountnumber;

【讨论】:

    【解决方案2】:

    不是$post_"username"。您应该使用$_POST["username"]; 从服务器 php 脚本中获取 post 参数。

    【讨论】:

      猜你喜欢
      • 2018-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多