jquery ajax统一对url编码,URL在jQuery中为AJAX请求编码字符串

6ca3b100bc1879ee148a855b84686125.png

繁花不似锦

encodeURIComponent对我来说很好。我们可以在ajax调用中给出这样的url。代码如下所示:  $.ajax({

    cache: false,

    type: "POST",

    url: "http://atandra.mivamerchantdev.com//mm5/json.mvc?Store_Code=ATA&Function=Module&Module_Code=thub_connector&Module_Function=THUB_Request",

    data: "strChannelName=" + $('#txtupdstorename').val() + "&ServiceUrl=" + encodeURIComponent($('#txtupdserviceurl').val()),

    dataType: "HTML",

    success: function (data) {

    },

    error: function (xhr, ajaxOptions, thrownError) {

    }

  });