Sunil Kumar
Sunil Kumar

Reputation: 1349

how to handle encoding while sending value via ajax

In wordpress, i am making an ajax call and sending this value

blow = \'blo\

But when i receive the value at the server end it has one \ extra

blow = \\'blo\

As you can see a \ is extra. I used urldecode but it is also giving me the same result

Please help me to find out what i am doing wrong

this is my script here are i serialize the form and in form i place in a text box blow = \'blo\

jQuery.ajax({
    type: 'POST',
    beforeSend: function () {
        var Container = jQuery("#mainContainer");
        var height = Container.height();
        var width = Container.width();
        jQuery('#le_form_container').css("display", "none");
        Container.append('<div class="loadingOverlay" style="width: 100%; height: 100%;" ><img class="ajaxLoading" src="' + url + '/leasson_Evalution/images/ajax_loader_blue_512.gif" /></div>');
    },
    url: ajaxcontactajax.ajaxurl,
    data: {
        action: 'ajaxcontact_send_mail',
        values: jQuery('#le_form').serialize().replace(/\+/g, '%20')
    },
    success: function (data, textStatus, XMLHttpRequest) {
        //console.log(data);
        if (data == 0) {
            jQuery("#le_SucessDialog").html('');
            jQuery('#le_SucessDialog').append("<p>Data is Submited</p>"); //alert(data is );
            jQuery("#le_SucessDialog").dialog({
                draggable: true
            });
            //console.log("tenp");
            jQuery("#le_form")[0].reset();
            //console.log("tenp");
        }
        //console.log(data);
    }, 
    error: function (MLHttpRequest, textStatus, errorThrown) {
        alert(errorThrown);
    },
    complete: function () {
        jQuery('#le_form_container').css("display","block");
        jQuery("#mainContainer").find(".loadingOverlay").hide().remove();
        jQuery("#le_form")[0].reset();
    }
});}

Upvotes: 1

Views: 101

Answers (2)

Alex.Me
Alex.Me

Reputation: 616

Use stripslashes:

$values = stripslashes($_POST["values"]);

Upvotes: 1

Nitin Dhapte
Nitin Dhapte

Reputation: 1

Try this : reset your variable with the escape

escape(blow)

Upvotes: 0

Related Questions