我正在尝试通过jQuery将表单发送到PHP文件。问题是,必须发送到PHP文件的内容包含斜杠(/
),因为里面有BBcode。
所以我尝试了以下内容:
$.ajax(
{
type: "POST",
url: "create.php",
data: "content=" + encodeURIComponent(content),
cache: false,
success: function(message)
{
$("#somediv").html(message);
}
});
在PHP文件中,我使用rawurldecode()
对内容进行解码并返回我的BBcodes,然后我可以将其转换为HTML。问题是,只要我输出encodeURIComponent()
它就会输出:[object HTMLTextAreaElement]
这是什么意思,我的错误在哪里?
答案 0 :(得分:5)
将数据打包为对象文字,并让jquery担心脏信息:
// 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.
答案 1 :(得分:1)
你的content
变量是textarea元素,而不是textarea中的文本(如果那是你要找的东西,因为你没有陈述content
是什么)
答案 2 :(得分:0)
不太确定,但变量content
的值似乎是HTML元素,而不是HTML元素的内容。
在您的代码的其他地方,您可能会有以下内容:
var content = $("selector");
......但它应该是:
var content = $("selector").val();
如果没有看到你的其他代码,就无法确定,但这对我来说就是这样。