ajax跨域調用

環境: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=?,必須傳入,否則不能實現跨域

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章