2015-03-13 93 views
1

我在窗体的文本区域使用内嵌编辑,它应该是,但当文本是字符串包含&登录它只能保存到&符号。所以我怎么可以在JavaScript的URL编码&登录,所以我的PHP脚本得到它,并保存在mysql为&再次。 这是我当前的代码和desc是可能包含&迹象偶尔发送字符串&登录ajax jquery post

var field_userid = $(this).attr("id") ; 
    var desc = $(this).val() ;  

    $.post('includes/update-property-modal.php' , field_userid + "=" + desc, function(data){ }); 
+0

你试过设置'processData'假? – skip405 2015-03-13 13:52:39

+0

我认为你应该尝试使用[jQuery.serialize](http://api.jquery.com/serialize/)来获取在Ajax中发送的值。 – vdubus 2015-03-13 13:57:49

+0

发送数据=> {{field_userid:desc}' – lshettyl 2015-03-13 14:01:40

回答

1

如果您想按照您目前的方式进行操作,则需要对其进行编码。

$.post('includes/update-property-modal.php' , field_userid + "=" + encodeURIComponent(desc), function(data){ }); 
+0

正是我所期待的。谢谢 – 2015-03-13 14:13:15

1

为什么不直接使用一个对象的字符串?

var self = this, 
    params = {}; 

params[self.id] = self.value; 

$.post('includes/update-property-modal.php',params,function(data){ 
    // whatever thine wish may be 
}); 

这应该管理的“&”内部存在,并且真的是更好的方式来与$.ajax()发送参数。

0

使用encodeURIComponent()可以转义除下列字符以外的所有字符:字母,小数位,_ - 。 〜! *'()

$.post('includes/update-property-modal.php', field_userid + "=" + encodeURIComponent(desc), function(data) {}); 

但在jQuery的阿贾克斯()和你的例子的情况下,最好是使用这种方式:

var params = { 
    $(this).attr('id'): $(this).val() 
}; 
$.post('includes/update-property-modal.php', params, function(data) {});