Query cross-domain introduction

 
 
jquery example:
var url = "http://s" + searchpage.sendcount + ".hqbuy.com/ajax/search";
        $.ajax({
            url: url,
            type: "Get",
            data: {
                "Keyword": encodeURIComponent(Keywords),
                "Qty": SrchNumber,
                "Token": token,
                "Channel": channel
            },
            crossDomain: true,
            dataType: "jsonp", //Specify the data type returned by the server
            error: function (error) {
                console.log(error);
            },
            success: function (response, status, xhr) {
                console.log(response);
            }
        });

backend interface

public string Search(string Token,string Keyword,int Qty,string Channel,string callback)
        {
            List<HQBuy.WebSearch.Model.SearchPicEntity> result = new List<HQBuy.WebSearch.Model.SearchPicEntity>();
            if (string.IsNullOrEmpty(Token))
            {
                return callback + "(" + Newtonsoft.Json.JsonConvert.SerializeObject(result) + ")";
            }
            if (string.IsNullOrEmpty(SearchKeyword))
            {
                return callback + "(" + Newtonsoft.Json.JsonConvert.SerializeObject(result) + ")";
            }
        }
Note: jsonp cross-domain, the interface needs to accept the callback parameter, if there is no callback, an exception will be reported. If ajax returns was not called, the callback is generally wrong.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324909611&siteId=291194637