访问函数中的javascript数据

Accessing javascript data in a function

本文关键字:javascript 数据 函数 访问      更新时间:2023-09-26

我有这个函数:

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,

在上面的代码中。我需要做些什么才能让它发挥作用?

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!");
             }
        });
}