项目用.net mvc做的,项目中用到juqery.post调用web api,web api方法申明如下,editLecture(int uid ,Exam_DOCS edoc,s)
其中第二个参数是一个model.在js中有相同结构的一个model,结构如下:
var Exam_DOCS = function () {
this.ownerid = "";
this.readtimer = 0;
this.s = "";
this.thumbimg = "";
this.wbrief = "";
this.wordcontent = "";
this.wordgrade = 0;
this.wordid = 0;
this.wordscount = 0;
this.words = "";
this.wordtitle = "";
this.wordtype = 0;
}
js中调用此api方法的代码如下(调用网站和web api是两个不同的网站):var url = "http://localhost:1789/Lecture/editLecture";
var params= new Exam_DOCS()
params.uid = 14
params.s = "ssss"
$.ajax({
type: "POST",
url: url,
dataType: "json",
data: params,
async: true,
processData: true,
success: function (html) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("异步提交出错!");
}
});结果直接出现错误,没有进入web api中相应方法的断点,错误信息如下:
XMLHttpRequest: 网络错误 0x80070005, 拒绝访问。
跨域问题已解决过了,同一api中还有其它get方法,调用成功,这个editLecture是HttpPost,调用失败
我猜了一下,很可能的原因出现在第二个参数edoc中,是不是实体类型的传参方式与普通参数不同,也有可能HttpPost和HttpGet调用方式不同,初学web api,请大家指教。Web APIjquery
其中第二个参数是一个model.在js中有相同结构的一个model,结构如下:
var Exam_DOCS = function () {
this.ownerid = "";
this.readtimer = 0;
this.s = "";
this.thumbimg = "";
this.wbrief = "";
this.wordcontent = "";
this.wordgrade = 0;
this.wordid = 0;
this.wordscount = 0;
this.words = "";
this.wordtitle = "";
this.wordtype = 0;
}
js中调用此api方法的代码如下(调用网站和web api是两个不同的网站):var url = "http://localhost:1789/Lecture/editLecture";
var params= new Exam_DOCS()
params.uid = 14
params.s = "ssss"
$.ajax({
type: "POST",
url: url,
dataType: "json",
data: params,
async: true,
processData: true,
success: function (html) {
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("异步提交出错!");
}
});结果直接出现错误,没有进入web api中相应方法的断点,错误信息如下:
XMLHttpRequest: 网络错误 0x80070005, 拒绝访问。
跨域问题已解决过了,同一api中还有其它get方法,调用成功,这个editLecture是HttpPost,调用失败
我猜了一下,很可能的原因出现在第二个参数edoc中,是不是实体类型的传参方式与普通参数不同,也有可能HttpPost和HttpGet调用方式不同,初学web api,请大家指教。Web APIjquery
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货