如何将输入值传递给ajax

时间:2015-11-19 16:48:10

标签: javascript php html ajax

好的,我是Ajax的新手。我的问题是,我不确定如何检索<input>标记中的数据并将其发送到Ajax。我试过在互联网上搜索,但大多数解决方案都使用jQuery Ajax,这是我目前不想要的。

这是我的代码。

我想保存这个值,以便我的Ajax可以读取它......

<input id="IDValue" name="IDValue" value="<?php echo $row['exist']?>" >

这是我的Ajax脚本......

 function message(){
    var ID=$(".IDValue").val();
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
             document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                            }
                        };
             xmlhttp.open("POST","retrieveMsg.php?q=" +ID,true);
             xmlhttp.send();
               }

请帮帮我,伙计们。我这样做的原因是因为(我以前的帖子)Send input value to php using ajax with result printed to div

2 个答案:

答案 0 :(得分:3)

替换它

 var ID=$(".IDValue").val();

使用

 var ID = document.getElementById("IDValie").value;

答案 1 :(得分:0)

我对你的$ row [&#39;存在&#39;]返回值感到困惑,以及你用于id =&#34; txtHint&#34;的html控件。在这里,我以某种方式提供了与您的代码相同的演示...尝试并根据您的要求进行更改...

frameworkAssemblies
相关问题