简体   繁体   中英

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.

$('.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:

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

   return false;

}

I want the HTML content need to displayed. 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.
Sending a POST request instead solves the problem of disallowed characters too.
You can find a solution for this here: Window.open and pass parameters by post method

add the special characters to variable $config['permitted_uri_chars']

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

in your config.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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