环境:(后台),采用asp.net mvc1
(前台),采用asp.net mvc1
上代码:
前台返回json数据:
public class ShowController : Controller
{
IAdvertisementService _advService = IoC.Resolve<IAdvertisementService>();
public string GetAdv(string keyword, string jsoncallback)
{
if (string.IsNullOrEmpty(keyword))
{
return jsoncallback + "({'result': 'false', message: '关键字为空',code:'keyword empty'})";
}
}
}
后台ajax获取json数据
//跨域测试
function kkkk() {
$.getJSON('http:///Show/GetAdv?keyword=化工&jsoncallback=?', function(d) {
alert(d.result);
});
};
关键点是url中参数jsoncallback=?,必须传入,否则不能实现跨域
















