0

如何将 ajax 发布的结果放入变量中:

function decode_original(hshdecode) {   
    var decode_original = 'decode=1&hashvalue=kjh4k5hq35l&hashkey=12345';
    $.ajax({
            type: "POST",
            async: false,
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            url: 'decode_function.php',
            data: decode_original,
            cache: false,
            success: function(return_value) {
                    var decoded_value = return_value;
                    console.log("Decoded Value:" +decoded_value);   
                    return decoded_value;
            },
            error: function(data){
                    return data;
            }
        });     
}

上面实际上成功获取了返回值,但是我无法将结果传递给变量:

var decode_value = decode_original(encoded_value);
        alert(decode_value);
4

1 回答 1

0

使用responseText像:

success: function(return_value) {
                    var decoded_value = return_value.responseText;
                    console.log("Decoded Value:" +decoded_value);   
                    return decoded_value;
            }
于 2012-04-25T13:32:15.550 回答