2012-11-28 13 views
5

मेरे पास संग्रह में नया मॉडल बनाने के लिए निम्न कोड है। अंतर्निहित डेटासंग्रह एक दूरस्थ एपीआई है:बैकबोन मॉडल। किसी भी कॉलबैक को कॉल न करें

 var postCreationStatus = this.model.create(newPostModel, { 
      wait : true  // waits for server to respond with 200 before adding newly created model to collection 
     }, { 
      success : function(resp){ 
       console.log('success callback'); 
       console.log(resp); 
      }, 
      error : function(err) { 
       console.log('error callback'); 
       console.log(err); 
      } 
     }); 

नया मॉडल बनाया जाता है, और मैं डेटाबेस से इस बात की पुष्टि कर सकते हैं, लेकिन न तो सफलता है और न ही त्रुटि कॉलबैक कहा जाता है मिलता है।

निर्माण पूरा होने के बाद, मैं उपयोगकर्ता को रीडायरेक्ट करना चाहता हूं। रीडायरेक्टिंग समय से पहले AJAX अनुरोध को मारता है, यही कारण है कि मैं सफलता कॉलबैक का उपयोग करना महत्वपूर्ण है।

सर्वर JSON प्रतिक्रिया { id : 11 } और 200 OK की HTTP स्थिति के साथ प्रतिक्रिया करता है।

+1

यह शीर्षक गलत है, यह प्रश्न संग्रह.क्रेट के बारे में नहीं है –

उत्तर

6

रीढ़ की हड्डी कोड में देखकर, मुझे एहसास हुआ कि create() फ़ंक्शन में मेरा कॉल गलत था। दूसरी तर्क के रूप में पारित होने वाली वस्तु के भीतर सफलता और त्रुटि कॉलबैक की आवश्यकता होती है, न कि तीसरे तर्क के रूप में। बदले गए, और काम करने वाले स्निपेट यह हैं:

var postCreationStatus = this.model.create(newPostModel, { 
    wait : true, // waits for server to respond with 200 before adding newly created model to collection 

    success : function(resp){ 
     console.log('success callback'); 
     console.log(resp); 
     that.redirectHomePage(); 
    }, 
    error : function(err) { 
     console.log('error callback'); 
     // this error message for dev only 
     alert('There was an error. See console for details'); 
     console.log(err); 
    } 
}); 
संबंधित मुद्दे