我有我的WebApi,它返回一个列表,并且还获取一个键值对列表
public List<myCustomers> GetCustomerDetails(List<KeyValuePair<string, string>> searchCriteria)
{
}
我使用ajax将服务称为:
jQuery.support.cors = true;
$.ajax({
url: 'http://MYSERVER/VCCSearchRestService/api/VCCSearch/GetCustomerDetails?
searchCriteria=WhatShoudIPassHere',
dataType: 'jsonp',
jsonpCallback: 'MyJSONPCallback',
type: 'GET',
// specify the callback name if you're hard-coding it
success: function (data) {
// we make a successful JSONP call!
}
});
答案 0 :(得分:0)
使用后置方法
public List<myCustomers> PostCustomerDetails(List<KeyValuePair<string, string>> searchCriteria)
{
{
Ajax Call
var keyvaluepair = [{"key1","value1"},{"key2","value2"}];
$.ajax({
url: 'http://MYSERVER/VCCSearchRestService/api/VCCSearch/PostCustomerDetails',
dataType: 'json',
jsonpCallback: 'MyJSONPCallback',
data: JSON.stringify(keyvaluepair); // pass list here
type: 'POST',
// specify the callback name if you're hard-coding it
success: function (data) {
// we make a successful JSONP call!
}
});