本文介绍了使用jQuery岗位ASP.Net的WebAPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到了一些麻烦:

我做这个简单的测试和警报弹出文本测试返回简单:

I do this simple test and the alert pops up the text "test return simple":

jQuery的岗位:

jQuery post:

$.post("http://www.localhost/webapi/api/corkboard/test/", jsonData)
            .done(function(data){
                alert(data);
        });

Asp.Net的WebAPI:

Asp.Net WebAPI:

[HttpPost]
public string test()
{
    return "test return simple";
}

但是,当我加入一个参数改变的WebAPI:

But when I change the WebAPI by adding a parameter:

public string test(string JSONData)
    {
        var jData = Json.Decode(JSONData);
        return "test return: " + jData.Filter;
    }

我收到以下错误信息:

I get the following error message:

没有HTTP资源发现,请求URIhttp://www.localhost/webapi/api/corkboard/test/'

"No HTTP resource was found that matches the request URI 'http://www.localhost/webapi/api/corkboard/test/'

卡住,将AP preciate任何想法...谢谢!

Stuck and would appreciate any thoughts ... thanks !

推荐答案

更改您的WebAPI的方法:

Change your WebApi method to:

public string test([FromBody]string JSONData)
    {
        var jData = Json.Decode(JSONData);
        return "test return: " + jData.Filter;
    }

和您的jQuery来:

and your JQuery to:

$.post('http://www.localhost/webapi/api/corkboard/test/', { '': jsonData })
        .done(function(data){
            alert(data);
    });

这篇关于使用jQuery岗位ASP.Net的WebAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 14:25