【问题标题】:how to handle encoding while sending value via ajax通过ajax发送值时如何处理编码
【发布时间】:2014-06-25 05:12:59
【问题描述】:

在 wordpress 中,我正在进行 ajax 调用并发送此值

blow = \'blo\

但是当我在服务器端收到值时,它有一个 \ 额外的

blow = \\'blo\

如您所见,\ 是额外的。我使用了 urldecode,但它也给了我相同的结果

请帮我找出我做错了什么

这是我的脚本,我将表单序列化并在表单中放入文本框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();
    }
});}

【问题讨论】:

  • 你将不得不向我们展示一些代码。
  • @meagar 编辑问题请检查代码
  • 确保你在服务器上禁用了magic_quotes。

标签: javascript php jquery ajax wordpress


【解决方案1】:

使用stripslashes:

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

【讨论】:

    【解决方案2】:

    试试这个:用转义符重置你的变量

    escape(blow)
    

    【讨论】:

    • 实际上吹 = \'blo\ 是写入文本框中的完整值,我将此文本框值发送到服务器端请检查编辑的问题
    猜你喜欢
    • 2020-08-31
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 2015-08-23
    • 2020-03-17
    • 2012-07-28
    • 1970-01-01
    相关资源
    最近更新 更多