2

ajax postを使用してURL文字列を送信しようとしていますが、文字列が自動エンコード(%25)または省略されている理由がわかりません

url = http://www.domain.com.br/berco-elegance-wave-verde-ayoba%2521-6343.html

php受信: http: //www.domain.com.br/berco-elegance-wave-verde-ayoba%21-6343.html

Firebugで投稿データを確認し、URL文字列はすでに変更されています:POST DATA url: http: //www.domain.com.br/berco-elegance-wave-verde-ayoba%21-6343.html

私のjqueryコード:

function save_competitor() {
$.ajax({
    type: "post",
    url: "<?php echo base_url();?>admin/storeproduct/insert_competitor",
    data: "url="+$("#url"),
    dataType:"json",
    contentType : "application/x-www-form-urlencoded; charset=UTF-8",
    success: function (data) {
        if(data.success){
            alert('ok');
        }else{
            alert('error');
        }
    },
    error: function (request, status, error) {
        if(status=='parsererror')
            window.location.href = 'auth/login/';
    }
});
}

HTML:

<input type="text" id="url" name="url" value="http://www.domain.com.br/berco-elegance-wave-verde-ayoba%2521-6343.html"/>
4

3 に答える 3

0

$( "#url")は要素を返しませんか?

$("#url").val()
or
$("#url").attr('href')
于 2012-12-03T13:01:36.760 に答える
0

dataあなたはすでにエンコードされたhtmlテキストからあなたを取得します。$( "#url")htmlコードの一部がどのように見えるかを教えてください。

編集 :

働き :

function urldecode(str) {
    return decodeURIComponent((str+'').replace(/\+/g, '%20'));
}

使用法 :

data: "url="+urldecode($("#url").text());

于 2012-12-03T13:03:49.860 に答える
0

URL Endoding References:

space   %20
    !   %21
    "   %22
    #   %23
    $    %24
    %   %25
    &   %26
    '   %27
    (   %28
    )   %29
    *   %2A
    +   %2B
    ,   %2C
    -   %2D
    .   %2E
    /   %2F
   .....

encodeURIComponentdecodeURIComponentはこの問題を解決します

encodeURIComponent(url);
decodeURIComponent(url)
于 2012-12-03T13:04:13.147 に答える