Liaison de données simple

Je suis nouveau sur Jquery Mobile. J’essaie de lier des données à une liste. ci-dessous est mon code. quand je cours la page ça ne montre pas la listview. s’il vous plaît aider.

Ma méthode de service

[WebMethod] public static ssortingng[] GetNames() { ssortingng[] names = {"chamara","janaka","asanka" }; return names; } 

Mon code HTML:

 

demo

$.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "PINCWebService.asmx/GetNames", endlessScroll: true, dataType: "json", success: function (data) { $("#car-data").html(data); }, failure: function (msg) { alert(msg); } });

entrez la description de l'image ici

J’ai écrit des choses pour vous. S’il vous plaît trouver comment chacune des choses sont faites.

Un service

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Script.Serialization; namespace SimpleWebService { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService { [WebMethod] public ssortingng GetLankanList() { JavaScriptSerializer serializer = new JavaScriptSerializer(); List lankanList = new List(); ssortingng[] names = { "chamara", "janaka", "asanka" }; for (int i = 0; i < names.Length; i++) { Lankans srilankans = new Lankans(); srilankans.Name = names[i]; lankanList.Add(srilankans); } string jsonString = serializer.Serialize(lankanList); return jsonString; } public class Lankans { public string Name { get; set; } } } } 

HTML

    Page Title      

Page Title

Page Footer

JavaScript

 $('#lankalistpage').live('pageshow',function(event){ var serviceURL = 'service1.asmx/GetLankanList'; $.ajax({ type: "POST", url: serviceURL, data: param="", contentType:"application/json; charset=utf-8", dataType: "json", success: successFunc, error: errorFunc }); function successFunc(data, status){ // parse it as object var lankanListArray = JSON.parse(data.d); // creating html ssortingng var listSsortingng = '
    '; // running a loop $.each(lankanListArray, function(index,value){ listSsortingng += '
  • '+this.Name+'
  • '; }); listSsortingng +='
'; //appending to the div $('#LankanLists').html(listSsortingng); // refreshing the list to apply styles $('#LankanLists ul').listview(); } function errorFunc(){ alert('error'); } });

Sortie finale entrez la description de l'image ici

Vous pouvez télécharger la source ici