简体   繁体   English

如何将.html()值从JavaScript传递到CodeIgniter控制器?

[英]How to pass .html() value from JavaScript to CodeIgniter controller?

I have a print button and when it is clicked the following JavaScript function must be triggered. 我有一个打印按钮,当单击它时,必须触发以下JavaScript函数。

$('.print').click(function(){
    var htmlval=$('.pop_reciept').html();
    window.open('http://localhost/ccccccc/xxxxxxx/pdf/'+htmlval,'_blank');                                  
});

htmlval contains the HTML of elements with the class pop_reciept , and then I pass this to the pdf controller: htmlval包含具有pop_reciept类的元素的HTML,然后将其传递给pdf控制器:

public function pdf($val){
   echo $val;

   return false;

}

I want the HTML content need to displayed. 我想要显示HTML内容。 But it is not, and instead I see the error 但事实并非如此,相反,我看到了错误

The URI you submitted has disallowed characters. 所提交的网址带有不被接受的字符。

Please help or suggest a better way to do this. 请帮助或建议一种更好的方法。

The size of url is limited to 8kb at most servers, great chunks of html code can easily exceed it. 在大多数服务器上,URL的大小限制为8kb,很大一部分html代码可以轻易超过它。
Sending a POST request instead solves the problem of disallowed characters too. 发送POST请求也可以解决字符不允许的问题。
You can find a solution for this here: Window.open and pass parameters by post method 您可以在此处找到解决方案: Window.open并通过post方法传递参数

add the special characters to variable $config['permitted_uri_chars'] 将特殊字符添加到变量$config['permitted_uri_chars']

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_=+-'; 

in your config.php 在您的config.php中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM