2014-10-30 80 views
2

我有這樣的功能:訪問的功能的JavaScript數據

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, 

在上面的代碼中。我需要做些什麼來完成這項工作?

+3

'「...... thanks?id =」+ json.id' – andlrc 2014-10-30 16:51:39

+0

完美。想讓它成爲答案並接受不適? – MikeHolford 2014-10-30 16:54:26

+0

更好的只是關閉你的問題:)這是一個簡單的印刷錯誤,它不屬於SO。 – andlrc 2014-10-30 16:56:44

回答

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

     }); 
}