2015-03-13 60 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) {}); 
相關問題