存储的JavaScript选择选项到PHP变量 [英] Store javascript select option into php variable

查看:97
本文介绍了存储的JavaScript选择选项到PHP变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要从一个HTML选择下拉值并将其存储到一个PHP变量。我敢肯定,这必须在AJAX做,但我不知道的细节。是否有可能得到选项字段的该值,并将其存储到一个PHP变量这种方式?

I want to retrieve a value from a HTML selection drop-down and store it into a PHP variable. I'm sure this has to be done in AJAX, but I'm not sure on the details. Is it possible to get that value of the option field and store it into a PHP variable this way?

$("#files").change(function() {
    $.ajax({
        type: "POST",
        url: "parse.html",
        data: {$'files'= $(this).val()},
        success: function(response) {
            //lolwut?
        }
    });
});

我想将其存储在一个PHP变量 $ X 就是我刚才标记它。选择是标题文件

I want to store it in a php variable $x is what I just labeled it. The selection is title files.

感谢。

推荐答案

您是pretty的接近。 AJAX调用的数据部分应包含一个键/值对。例如:

You're pretty close. The data portion of the AJAX call should contain a key/value pair. Example:

data: {selectVal : this.value},

现在你的PHP后台,你可以检索的变量:

Now on your PHP backend, you can retrieve the variable with:

$selectValue = $_POST['selectVal'];

用它做你想要什么,你可以返回任何你想要的客户端以及与回声。不管你回声回来,现在可以在你的变量响应拿起了AJAX的成功回调

Do with it what you want, and you can return whatever you want to the client-side as well with echo. Whatever you echo back can now be picked up in the AJAX success callback under your variable response.

此外,设置你的网​​址到PHP页面的URL。

Also, set your url to your PHP page url.

这篇关于存储的JavaScript选择选项到PHP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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