Convert AJAX call from jQuery 1.4 to 1.8
I have the following code that works well if I use jQuery 1.4 however I would like to upgrade to latest version 1.8 and this code returns '0 error' when jQuery above 1.5 is used.
Would someone know what i need to change to make it 1.8 compatible please.
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>PA Web Test</title>
- <script src="jquery-1.8.0.js" type="text/javascript"></script>
- <script type="text/javascript">
-
- var offset = 0;
- var howMany = 5;
-
- $(document).ready(function() {
- $("#btnMore").click(function() {
- // fetch some more records from the server side
- $.ajax({
- type: "POST",
- dataType: "json",
- contentType: "application/json; charset=utf-8",
- url: "http://localhost/PA_Web.asmx/GetData",
- data: "{'offset':" + offset + ",'howMany':" + howMany + "}",
- success: onSuccess,
- error: onError
- });
- });
- });
- function onSuccess(result) {
- // process web service return data
- // populate ul with data
- $("#datalist").empty();
- var strings = result.d;
- for (var i = 0; i < strings.length; i++)
- $("#datalist").append("<li>" + strings[i] + "</li>");
- // move offset
- offset += howMany;
- }
- function onError(result) {
- // ajax call failed
- alert(result.status + ': ' + result.statusText);
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <ul id="datalist"></ul>
- <br />
- <input type="button" id="btnMore" value="more" />
- </div>
- </form>
- </body>
- </html>