Home  >  Article  >  Web Front-end  >  jquery gets json data implementation code_jquery

jquery gets json data implementation code_jquery

WBOY
WBOYOriginal
2016-05-16 18:53:461341browse
Copy code The code is as follows:

//Column
//Send ajax request
$ .getJSON(
"../../../Templet/GetInfoHandler.ashx", //Server page that generates JSON data
{id: "0", sid: "1;2;3 ", rid: Math.round(Math.random() * 10) }, //Query string sent to the server
//Process the returned JSON data
function(json) {
//Loop through the data in json and present it in the list
$("#column_0_1").empty();
var colstr = '

More>>Popular Recruitment

    ';
    $.each(json, function(i ) {
    //alert(json[i].news_id);
    colstr = colstr '
  • ' json[i].news_title '< /li>';
    })
    colstr = colstr '
';
$("#column_0_1").html(colstr);
alert("Loading successful") ;
// })

C# program to generate json data using Litjson:
Copy code The code is as follows:

//Column
//Send ajax request
$.getJSON(
"../../../Templet/GetInfoHandler.ashx ", //Server page that generates JSON data
{id: "0", sid: "1;2;3", rid: Math.round(Math.random() * 10) }, //To Query string sent by the server
//Process the returned JSON data
function(json) {
//Loop through the data in json and present it in the list
$("# column_0_1").empty();
var colstr = '

More>>< ;/span>Popular Recruitment

    ';
    $.each(json, function(i) {
    //alert(json[i].news_id);
    colstr = colstr '
  • ' json[i].news_title '
  • ';
    })
    colstr = colstr '$("#column_0_1").html(colstr);
    alert("Loading successful");
    // })

jquery obtained through json Data
Copy code The code is as follows:



html code:
Copy code The code is as follows:



Ajax:
Create a new .aspx page, delete the html code in the .aspx page, and add the following code in .aspx.cs
Copy code The code is as follows:

string rq_basecode=null;
rq_basecode = Request.QueryString["code"];
if (string.IsNullOrWhiteSpace(rq_basecode))
{
Response.Write("Error");
Response.End();
}
BLLCataLog bll_info = new BLLCataLog();
List lt_info = new List();
lt_info = bll_info.GetCatalog(rq_basecode,"");
//Response.Write(rq_basecode);
if (lt_info.Count > 0)
{
Response.Write(JsonHelper.ToJson(lt_info));
}
else
{
Response.Write("Null");
}

BLL层的数据:
复制代码 代码如下:

public List GetCatalog(string code, string refcode)
{
DALCataLog dalcatalog6 = new M2SharpDAL.DALCataLog();
return dalcatalog6.GetCatalog(code, refcode);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn