在淘汰赛js中的MVC Web API中的post方法 [英] post method in MVC Web API in knockout js

查看:50
本文介绍了在淘汰赛js中的MVC Web API中的post方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要使用Knockout js在MVC web API上发布post,delete,put方法的示例和示例。我在MVC web API中运行Post方法时出错了。请尽快给出解决方案。



这里我的帖子方法代码:



 $ .ajax({
url:'api / product / PostProduct /',
cache:false,
type:'POST',
contentType:'application / json; charset = utf-8',
数据:ko.toJSON(产品),
成功:函数(数据){
alert('added');
self.Products.push (数据);
self.BrandName();
self.price();
self.GenericName();
}
} ).fail(
函数(xhr,textStatus,err){
alert('error');
});

解决方案

.ajax({
url:'api / product / PostProduct /',
cache:false,
type:'POST',
contentType:'application / json; charset = utf-8',
data:ko.toJSON(Product),
成功:函数(数据){
alert('added');
self.Products.push(data);
self.BrandName();
self.price ();
self.GenericName();
}
})。失败(
函数(xhr,textStatus,err){
alert( '错误');
});


 url:'  api / product / PostProduct /'



此行标识地址而非方法(注意结尾 / 字符!!!)

您应该这样编写(其中PostProduct是服务器端方法的名称)

 url:'  api / product / PostProduct'


Hi,

i need samples and examples for post,delete,put method on MVC web API with Knockout js. i got an error while running Post method in MVC web API. pls give solution ASAP.

here my code for Post Method:

$.ajax({
                       url: 'api/product/PostProduct/',
                       cache: false,
                       type: 'POST',
                       contentType: 'application/json; charset=utf-8',
                       data: ko.toJSON(Product),
                       success: function (data) {
                            alert('added');
                           self.Products.push(data);
                           self.BrandName("");
                           self.price("");
                           self.GenericName("");
                       }
                   }).fail(
                        function (xhr, textStatus, err) {
                            alert('error');
                        });

解决方案

.ajax({ url: 'api/product/PostProduct/', cache: false, type: 'POST', contentType: 'application/json; charset=utf-8', data: ko.toJSON(Product), success: function (data) { alert('added'); self.Products.push(data); self.BrandName(""); self.price(""); self.GenericName(""); } }).fail( function (xhr, textStatus, err) { alert('error'); });


url: 'api/product/PostProduct/',


This line identifies an address and not a method (notice the ending / character!!!)
You should write it like this (where PostProduct is the name of your method on the server side)

url: 'api/product/PostProduct',


这篇关于在淘汰赛js中的MVC Web API中的post方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆