如何通过ajax调用将参数传递给web api [英] how pass parameters to web api through ajax call

查看:112
本文介绍了如何通过ajax调用将参数传递给web api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过ajax调用将参数传递给web api



这是我的代码,但它将null传递给name.why?这里有什么问题?

how pass parameters to web api through ajax call

this is my code,but it is passing null to name.why?what's wrong here?

function GetJson() {
    // Send an AJAX request
    $.ajax({
        type: "POST",
        url: "/api/Product",
        data:{name:'Hello'},
        dataType: 'json',
        success: function (response) {
            alert(response);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        }
    });
}

推荐答案

.ajax({
type: POST
url: / api / Product
data:{name:' Hello'},
dataType:' json'
成功: function (响应){
alert(response);
},
错误: function (xhr,ajaxOptions,thrownError){
alert(xhr.status);
alert(thrownError);
}
});
}
.ajax({ type: "POST", url: "/api/Product", data:{name:'Hello'}, dataType: 'json', success: function (response) { alert(response); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); }


data:JSON.stringify({name:'Hello'});试试这个或者看看这里了解更多
data: JSON.stringify({name:'Hello'}); try this or look here for more


这篇关于如何通过ajax调用将参数传递给web api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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