访问函数中的javascript数据

时间:2014-10-30 16:50:42

标签: javascript function variables

我有这个功能:

function formSubmitted(json, grandTotal) {

    $.ajax({
            type: "POST",
            url: "../quotes/create",
            data: {
                quote: {
                  name: json.name,
                  json: JSON.stringify(json),
                  email: json.email,
                  uid: json.id,
                  grand_total: grandTotal,
                  postcode: json.postcode,
                }
            },
             dataType:'text',
             success: function(data,status,xhr){
                console.log(status);
                alert("AWESOME!");

                window.location.assign("http://www.example.com/thanks?id=json.id")
             },
             error: function(xhr,status,error){
               console.log(status,error);
               alert("ERROR!");
             }

        });
}

一切正常但我想做的是在成功时使用window.location重定向:到

http://www.example.com/thanks?id=json.id

json.id与

相同
uid: json.id,

在上面的代码中。我需要做些什么来完成这项工作?

1 个答案:

答案 0 :(得分:2)

function formSubmitted(json, grandTotal) {

    $.ajax({
            type: "POST",
            url: "../quotes/create",
            data: {
                quote: {
                  name: json.name,
                  json: JSON.stringify(json),
                  email: json.email,
                  uid: json.id,
                  grand_total: grandTotal,
                  postcode: json.postcode,
                }
            },
             dataType:'text',
             success: function(data,status,xhr){
                console.log(status);
                alert("AWESOME!");

                window.location.assign("http://www.example.com/thanks?id=" + json.id)
             },
             error: function(xhr,status,error){
               console.log(status,error);
               alert("ERROR!");
             }

        });
}