检索ajax请求的结果作为变量

时间:2012-04-25 13:29:04

标签: ajax variables

如何将我的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);

1 个答案:

答案 0 :(得分:0)

使用 responseText ,如:

success: function(return_value) {
                    var decoded_value = return_value.responseText;
                    console.log("Decoded Value:" +decoded_value);   
                    return decoded_value;
            }