<script type="text/javascript"> $(document).ready(function () { $.each(($.browser), function (i, val) { }); $("#btnlookup").click(function () { lookup(); }); }); if (!$.browser.msie) {alert('this utility is available only for IE, please try JSONP for other browsers'); return; }var addressURL = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + $("#txtAddress").val() + "&sensor=false"; alert(addressURL); $("#output").text(""); $.ajax({ url: addressURL, dataType: "xml", success: function (response) { if (!$.isXMLDoc(response)) { var outputStr = "Result is not valid XML Format"; $(outputStr).appendTo($("#output")); } $.each($(response).find('result'), function () { var outputStr = ""; $(outputStr).appendTo($("#output")); }); }, //sccess error: function (response) { var outputStr = "" + response.status + ""; $(outputStr).appendTo($("#output")); } }//ajax options ); } script>
Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts
Monday, January 17, 2011
JQuery XML parsing
JSON via webservices Using JSONP
//Step1 add ScriptService for the class & [ScriptMethod(UseHttpGet = true)]
//to the method////// Summary description for RatingService_JSONP /// [WebService(Namespace = "http://ws.cli.det.nsw.edu.au/ns/Web2Services/RattingService", Description = "Ratting service, this service will be plugable in any application, to support rating with comments, including reports and summaries")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class RatingService_JSONP : RatingService { } [WebMethod(Description = @"Sample Please remove it")] [ScriptMethod(UseHttpGet = true)] public string[] Sample() { return new string[] { "AAA", "BBB", "CCC", "DDD" }; } }
//Step2
// use format=json for json format
// use callback=? for JSONP
$(document).ready(function () { $("#btnlookup").click(function () { lookup(); }); }); function lookup() { var addressURL = "http://localhost/Web2Services/WebServices/JSON/RatingService_JSONP.asmx/Sample?format=json&callback=?"; var outputStr = ""; $("#output").text(outputStr); $.getJSON(addressURL, null, function (response) { $.each(response.d, function (i, val) { outputStr = ""; $(outputStr).appendTo("#output"); }); }); // getJson
Sunday, September 26, 2010
JQuery basic code
//Hook change for each option to an event<asp:Content ContentPlaceHolderID="ScriptPlaceHolder" ID="Scripts" runat="server">
<script type="text/jscript" language="javascript">
$(document).ready(function () {
$("#listSamples").change(function (event) {
if (this.value == 'RunSampleA') {
RunSampleA();
return;
}
if (this.value == 'RunSampleB') {
RunSampleB();
return;
}
if (this.value == 'RunSampleC') {
RunSampleC();
return;
}
if (this.value == 'RunSampleD') {
RunSampleD();
return;
}
}
)
}
);
script>
asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="div_content">
content;
<select id="listSamples">
<option value='NULL'>Choose Sampleoption>
<option value='RunSampleA'>Run Sample Aoption>
<option value='RunSampleB'>Run Sample Boption>
<option value='RunSampleC'>Run Sample Coption>
<option value='RunSampleD'>Run Sample Doption>
select>
div>
asp:Content>
Sunday, September 19, 2010
JQuery basic code
$(document).ready(function(){ $("a").click(function(event){ alert("Thanks for visiting!"); }); });
Subscribe to:
Posts (Atom)