来自BackboneJS的Ajax调用

时间:2014-12-05 11:59:05

标签: javascript jquery asp.net-mvc

如何从mvc控制器调用骨干操作,返回一个字符串。我需要能够在javascript中使用该字符串。从控制器调用操作。我只需要与jquery类似的功能:

$.ajax({
            type: 'POST',
            url: window.location + "Home/InsertRecord",
            data: {ID : newPersonName},
            success: function(data) {
                // Code after success },
                error: function(){
                    alert("error");
                }
            });

1 个答案:

答案 0 :(得分:0)

来自backbone.js的Ajax调用

//Model Declaration
var mod = Backbone. Model. extends ({});
var collection = Backbone.Collection.extend({
    model:Model
});

//Create Collection Object
newCollection = new collection();

//Make Ajax Call
Backbone.ajax({
    dataType: "jsonp",
    url: "http://example.com", //Replace your URL here
    data: "", //add your data
    success: function(response){
        //code after success
    }
    error: function () {
        // Code After Erroe
    }

}).complete(function () {
  //Code after complete the request
});

供参考,请查看此链接 http://backbonejs.org/#Model