0

I've googled and I've checked stackoverflow for an answer, but yet I haven't found a proper one. My input regularly contains & (ampersand) and @ so I would need to escape that variable CN99, how can i do this with jquery?

$("#CompanyNameFilter").focus(function() {
    var CN99 = $("#CompanyNameFilter").val();

    $.ajax({
        url: "clients.php?companyname=" + CN99,
        dataType: "html",
        success: function(html) {
            var div = $("#companyList", $(html)).addClass("done");
            $("#companyList").html(div);
        }
    });

});
Drazek
  • 341
  • 2
  • 7
  • 16

1 Answers1

1

You should pass the url parameters with the data option of ajax..

$("#CompanyNameFilter").focus(function() {
    var CN99 = $("#CompanyNameFilter").val();

    $.ajax({
        url: 'clients.php',
        data: {companyname: CN99},
        type: 'get',
        dataType: "html",
        success: function(html) {
            var div = $("#companyList", $(html)).addClass("done");
            $("#companyList").html(div);
        }
    });
});

This way jQuery will handle the encoding

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317