我有一个从textarea
提取的数据,如下所示:
TO WHOM IT MAY CONCERN: This is to certify that Mr/Ms JOHN SMITH is enrolled in this institution for this First Semester of School Year 2013-2014 as a second year Psychology student. Below is his/her STATEMENT OF ACCOUNT.
What I've tried?
var letter = $('#textarea_letter').val();
var myJSON = {"letter": letter };
var strJSON = JSON.stringify(myJSON);
$('#toPDF_button').attr('href', 'generate_pdf/'+ myJSON +'/pdf');
// this button then sends the letter to a function w/c generates the PDF
我得到了什么?
Error_404页面
我需要在参数url中传递字母,这是在url中的样子:
localhost/accounting/generate_pdf/{"letter":"TO WHOM IT MAY CONCERN:\n\t\t\t\t\t\t\tThis is to certify that Mr/Ms JOHN S> SMITH is enrolled in this institution for this First Semester of School Year 2013-2014\n\t\t\t\t\t\t\tas a second year BSIT student. Below is his/her STATEMENT OF ACCOUNT."}/pdf
我该怎么做?我是JSON的新手。谢谢
更新
完成此操作后
var myJSON = encodeURIComponent(JSON.stringify(myJSON1));
这是新的网址,但仍然出现相同的错误http://localhost/accounting/accounting/generate_sta/%7B%22letter%22%3A%22TO%20WHOM%20IT%20MAY%20CONCERN%3A%5Cn%5Ct%5Ct%5Ct%5Ct%5Ct%5Ct%5CtThis%20is%20to%20certify%20that%20Mr%2FMs%20JOHN%20SMITH%20G.%20SEBUCAO%20is%20enrolled%20in%20this%20institution%20for%20this%20First%20Semester%20of%20School%20Year%202013-2014%5Cn%5Ct%5Ct%5Ct%5Ct%5Ct%5Ct%5Ctas%20a%20second%20year%20Psychology%20student.%20Below%20is%20his%2Fher%20STATEMENT%20OF%20ACCOUNT.%22%7D/pdf
最佳答案
您无法原样发送JSON字符串-您必须对其进行编码。
为此有一个Javascript函数。
var strJSON = encodeURIComponent(JSON.stringify(myJSON));
这应该可以解决问题。