如何连接code含量他们通过jQuery发送到PHP文件? [英] How to encode content to send them via jquery to a php file?
问题描述
我想一个形式通过jQuery发送到PHP文件。问题是,该内容,其中有要发送到PHP文件,包含斜线( /
),因为有BB code内。
因此,我试过如下:
I am trying to send a form to a PHP file via jQuery. The problem is, that the content, which has to be sent to the PHP file, contains slashes (/
) since there is BBcode inside.
So I tried the following:
$.ajax(
{
type: "POST",
url: "create.php",
data: "content=" + encodeURIComponent(content),
cache: false,
success: function(message)
{
$("#somediv").html(message);
}
});
在我使用 rawurlde code()
脱code中的内容,并得到我的BB codeS回来,我可以那么PHP文件转换成HTML。这个问题一旦是因为我把连接codeURIComponent()
将输出: [对象HTMLTextAreaElement]
In the PHP file I use rawurldecode()
to decode the content and get my BBcodes back which I can then transform into HTML. The problem is as soon as I put the encodeURIComponent()
it will output: [object HTMLTextAreaElement]
这是什么意思,哪里是我的错?
What does that mean, where is my mistake?
推荐答案
包装您的数据作为对象文本,并让有关的肮脏细节jQuery的担心:
Package your data as an object literal, and and let jquery worry about the dirty details:
// javascript
$.post(
"create.php",
{
content: "here is my content / slashes included."
},
function( message ) {
$("#somediv").html( message );
}
)
///////////////////////////////////////////////
// php
$formData = $_POST["content"];
echo $formData;
// yields: here is my content / slashes included.
这篇关于如何连接code含量他们通过jQuery发送到PHP文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!