【问题标题】:send checkbox value with ajax to php将带有ajax的复选框值发送到php
【发布时间】:2014-10-02 10:30:08
【问题描述】:

在 ajax 中发送复选框值。

复选框值未发布到 php,此后整个脚本无法运行。 请有人告诉我我在哪里犯了错误并为此提供解决方案。

function ajaxFunction(str,str1,str2,str3)
        {
            var security = $('input[name="subfolder"]').prop('checked');
            var httpxml;
            try
            {
// Firefox, Opera 8.0+, Safari
                httpxml=new XMLHttpRequest();
            }
            catch (e)
            {
// Internet Explorer
                try
                {
                    httpxml=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                    try
                    {
                        httpxml=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    catch (e)
                    {
                        alert("Your browser does not support AJAX!");
                        return false;
                    }
                }
            }
            function stateChanged()
            {
                if(httpxml.readyState==4)
                {
                    document.getElementById("displayDiv").innerHTML=httpxml.responseText;

                }
            }


            var url="my-test-search.php";
            url=url+"?txt="+str+"&txt1="+str1+"&txt2="+str2+"&txt3="+str3+"&che="+security;
            url=url+"&sid="+Math.random();
            httpxml.onreadystatechange=stateChanged;
            httpxml.open("GET",url,true);
            httpxml.send(null);
        }



  <form id="myform" method="post">
                   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Search : <input type="text" id="search_text" name="search_text" size="44" >
                    Extension : <input type="text" id="search_extension" name="search_extension" size="4" maxlength="4"> <br><br>
                                  Include Sub Files <input type="checkbox" id="subfolder" name="subfolder" value="0">&nbsp;&nbsp;&nbsp;&nbsp;
                                   LTO-No. <input type="text" id="search_ltono" name="search_ltono" size="4" maxlength="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="buttonExecute" onclick="ajaxFunction(search_text.value,search_ltono.value,search_extension.value,subfolder.value)" type="button" value="Show&nbsp;&nbsp;" />

                        </form>

【问题讨论】:

  • 请试试这个链接:link

标签: ajax


【解决方案1】:

复选框没有属性值,但已检查属性。尝试使用:

subfolder.checked

并从标记中删除属性值

【讨论】:

  • 还是不行。如果我删除这一行 var security = $('input[name="subfolder"]').prop('checked');该脚本有效,但我希望将复选框值发送到 php。
猜你喜欢
  • 2013-12-25
  • 2015-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多