$ _GET does not catch "+"

0

I'm retrieving a value from an AJAX request, it works fine however it has a problem. The "+" character is replaced by a blank

Dell printer (supporting eSF 2.1+)

Stay

Dell printer (supporting eSF 2.1 )

And this is giving "bomb" in the system

 var XMLHttp =  generateXMLHttp();
    XMLHttp.open("get", "classes/getDataPropCom.php?qtd_embarcados=" + qtdUsuarios +"&id=" + id, true);
    XMLHttp.onreadystatechange = function () {

        if (XMLHttp.readyState == 4){
            if (XMLHttp.status == 200) {
            }
        }
});

Jquery takes the value with the "+" right Now the Ajax GET rescue does not catch the "+"

When he arrives here .... do not get the "+"

if(isset($_GET['qtd_embarcados']) && isset($_GET['id'])){
    $qtd_embarcados = $_GET['qtd_embarcados'];
    $id = $_GET['id'];

    if($qtd_embarcados != ''){
        if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
            /* special ajax here */
            $PropostaComercial->getValue($qtd_embarcados,$id);
        }else if(empty($usuarios)){
            $PropostaComercial->getValue($qtd_embarcados,$id);
        }
        else{
            $PropostaComercial->getValue($qtd_embarcados,$id);
        }
    }
}

How do I get the values

 if($("#ComercialEDEP10 h5").html() != undefined){
        id = encodeURIComponent($("#ComercialEDEP10 h5").html());
    }

    if($("#EducacionalEDEP10 h5").html() != undefined){
        id = encodeURIComponent($("#EducacionalEDEP10 h5").html());
    }
    if($("#ProfissionalEDEP10 h5").html() != undefined){
        id = encodeURIComponent($("#ProfissionalEDEP10 h5").html());
    }
    
asked by anonymous 16.08.2017 / 15:59

1 answer

2

You have to treat this string before sending it to ajax.

var string = 'Dell printer (supporting eSF 2.1+)';
var stringTratada = encodeURIComponent(string);

console.log(stringTratada);

So no characters are lost and it's in a standard format.

And in PHP if necessary (since $_GET already does this) you can use urldecode for convert it back to the readable string.

    
16.08.2017 / 16:08