Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 包含&;给定jquery ajax导致post变量出错?_Php_Jquery_Ajax_Html Entities - Fatal编程技术网

Php 包含&;给定jquery ajax导致post变量出错?

Php 包含&;给定jquery ajax导致post变量出错?,php,jquery,ajax,html-entities,Php,Jquery,Ajax,Html Entities,我有一个文本框,正在使用jqueryAjax检查文本的可用性。我面临着这样一个问题:当我检查jquery中包含&后变量的文本时,我检查了中给出的解决方案,但仍然是在我们为&获取html编码值时,它给出了&将再次具有&,因此jquery ajax post变量被破坏。下面给出了我尝试的代码 //from the text field var textfieldValue=$('#text').val(); //Jquery Ajax $.ajax({

我有一个文本框,正在使用jqueryAjax检查文本的可用性。我面临着这样一个问题:当我检查jquery中包含
&
后变量的文本时,我检查了中给出的解决方案,但仍然是在我们为
&
获取html编码值时,它给出了
&
将再次具有
&
,因此jquery ajax post变量被破坏。下面给出了我尝试的代码

    //from the text field
    var textfieldValue=$('#text').val();

    //Jquery Ajax
    $.ajax({
       type: "POST",
       async: false,
       url: "ajax/CheckAvailabilityphppage.php",
       data: "fieldvalue="+textfieldValue,
       dataType: "json",
       success: function(data){
         if (data['Status'] == 'YES'){
           alert('yes its Available');
          }else{
           alert('Sorry Not Available');
          }
       }
   });
在Firebug中,Post变量显示为(如果文本为p&p)

&p
作为另一个Post参数,因此ajax只验证文本
p

非常感谢您的帮助或建议


非常感谢

您需要正确地对值进行URL编码


用于此。

将对象传递给数据参数,jquery将自动为您编码

data: { fieldvalue: textfieldValue },

不,对不起,我试过了。。这行不通。。它不会编码&。当我在Firebug中编码后打印值时,我得到的文本
P&P
%2525255bject%25252520HTMLInputElement%2525255D
我在哪里错了吗..@Philemonphilipkunjumumon表明您缺少
.val()
您问题中的部分代码。请您再解释一下。如果是的话。Val()部分被遗漏了,然后当我执行console.log(textfieldValue)时,我得到了文本字段中的值……公平地说,如果这个方法起作用,CBroe的方法应该会起作用<代码>数据:“fieldvalue=“+encodeURIComponent(textfieldValue)”,
data: { fieldvalue: textfieldValue },