環境:micadmin.esunny.com(後臺),採用asp.net mvc1
mic.esunny.com(前臺),採用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://mic.esunny.com/Show/GetAdv?keyword=化工&jsoncallback=?', function(d) {
alert(d.result);
});
};
關鍵點是url中參數jsoncallback=?,必須傳入,否則不能實現跨域