【发布时间】:2012-11-15 15:21:52
【问题描述】:
在传递变量时,我的 ajax 代码一切正常,可以说“hello world”,但是当传递包含“hello world http//www.facebook.com”之类的变量时,实际上会导致很多问题。
实际上它是我遇到问题的变量“new_textarea”。 说清楚一点,
var new_textarea = "hello world"; //successfully saves it to database
但是当
var new_textarea = "http://www.facebook.com" // will lead to problems
这是我的 ajax 代码:
$.ajax({
url: '/learns/quickpostcomment/'+user_discussion_id+'/'+user_id+'/'+new_textarea+'/'+parent_id,
success: function(data){
}});
这是我的 cakephp:
public function quickpostcomment()
{
$post = $this->params['pass'];
$this->ClassroomComment->create();
$this->ClassroomComment->set('classroom_id', $post[0]);
$this->ClassroomComment->set('user_id', $post[1]);
$this->ClassroomComment->set('comment', $post[2]);
$this->ClassroomComment->set('parent_id', $post[3]);
$this->ClassroomComment->save();
die;
}
到目前为止,我检查的只是触发问题的是变量包含 url 时变量上的“/”或斜杠。
有什么方法可以将包含斜杠或 url 的变量传递给我的 ajax? 我非常需要帮助:(
【问题讨论】: