jQuery Ajax $.post issue : char "+" disappear

121 Views Asked by At

I'm working on a wysiwyg and a section to insert source code like PHP/HTML/Perl/etc...

I use de PHP Geshi for highlight the code via jQuery.

Everything work well, I get my code well but I lost the char "+" in the returned code.

I think the problem comes from the fact that "$.post" interpret "+" such as adding a new parameter in the sending, I just be wrong.

I'm not even POST or GET is the right solution to get source code with lots of weird characters ... I'm interested in new idea ...

The jQuery Code :

$('#valider_code').click(function() { 
    // On selectionne le contenue du textarea

    var code = $("#code").val();
    code = addslashes(code);
    // On cache le div
    $('#input_code').hide();

    $.post('/get_geshi.php', { "code" : code, "langage" : langage }, function(data) {

    data = data.replace(/\n|\r|\r\n/g, '<br>');
       // On insert le code
    var embed = '<div id="code_source">'+ data +'</div>';
        if($.browser.msie) {
            var selection = editor.contentWindow.document.selection;
            var range = selection.createRange();
            range.pasteHTML(embed);

        }
        else {
        execCommand("inserthtml", embed);
        }
        langage = "";
        code = $("#code").val('');


    }); // Fin get
    return false; // prevent default
  });

get_geshi.php

<?php
require_once('geshi.php');

$source = stripslashes(urldecode($_POST["code"]));

$language = $_POST["langage"];

$geshi =& new GeSHi($source, $language);
echo $geshi->parse_code();

?>
1

There are 1 best solutions below

1
On

Y enter this line (Perl code) :

$line =~ /\s+(\S+)$/;

It's return this line :

$line =~ /\s (\S )$/;

The "+" drop.