C # ASP. NET PhoneGap HTML5

Source: Internet
Author: User

Haven't written a blog for a long time, write an article for yourself today. Let's talk about C # PHONEGAP,HTML5 and ASP. The ability to search this blog means you are a. NET developer who is about to be or is working on mobile development.

Everyone may have doubts, I am a. NET developer, can use. NET to do Apple, Android, WP platform application?

As you know, PhoneGap is used to develop cross-platform mobile applications, and PhoneGap can invoke the mobile settings of the hardware interface, to achieve some ordinary HTML on mobile devices can not be implemented, such as photography, recording, recording video and so on.

To do the HTML5 page as a unit of the application, it must be with the server for data interaction. There are two scenarios that you think of interacting with the server:

One is the use of the default local HTML (of course, you can also put HTML on the server side, but this is not as good as using the second scenario), one is to use server scripts, such as JSP pages, of course, these pages must be placed on the server side, the client only need to refer to this page at the time of initialization, Android client, the code is as follows:

public class MyActivity extends Droidgap {
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Super.loadurl ("file:///android_asset/login.html");
Super.loadurl ("http://220.166.32.204:8080/test/login.jsp");
Super.setintegerproperty ("Loadurltimeoutvalue", 15000);
}
}

(commented out code is phonegap default local HTML scheme)

The other is that the HTTP request is the server scripting Solution

Each has its own advantages, the local HTML scheme can be code and server -side code isolation, maintenance only need to maintain the client, no need to modify the server side, and because it is read locally, You can use the application without network (you can save the resource in the local sqllite database); The server scripting solution benefits from a simple code, almost no difference to developing a plain web page, or even a Web page that was previously written for a PC. JS recognition device change CSS style dynamically.

I am using the local HTML5 solution, in the data interaction , using AJAX, using jquery ajax method, JS code is as follows:

function pullnoticelist () {
$.ajax ({
url:addr+ "notice_list.action",
Type: "POST",
DataType: "Jsonp",
data:{"start": "0", "Limit": "8", "Sort": "Effectivedate", "dir": "DESC"},
Befores End:function () {
$ ("#content"). HTML ("<p> data pull, please ...</p> later"). Trigger ("create");
},
Success:function (response) {
var starthtml = ' <ul id= ' ListView ' data-role= ' ListView ' Data-theme= "C" > ";
var endhtml = "<li id= ' more ' ><p >;
$.each (response.noticelist,function (index,item) {
starthtml+= "<li><a href=" Javascript:showDetail ("+item.noticeid+"); ' ><p> "+item.noticetitle+" <span class= ' ui-li-aside ' > "+item.effectivedate+" </span></p> </a></li> ";
});
$ ("#content"). HTML (starthtml+endhtml). Trigger ("create");
},
Error:function () {
showreconnconfirm ();
}
});
}

You must use the JSONP format, otherwise there is no return value, second, note the JSON format returned, be sure to conform to the JSON format of jquery, you can view the debug JSON through Firedug, Server End-use struts, you can use Struts's JSON plug-in to intelligently encapsulate objects in JSON format.

If you want to use PhoneGap to do a cross-platform application, first of all to determine whether to invoke the mobile device hardware interface, if not need to call, then the first scenario is the best choice, maintenance development and the usual web almost no difference, The best fit for our. NET developers, as we can directly choose to develop with ASPX pages.

However, if the project has a hardware interface that requires the mobile device to be called, then the second option must be chosen.

At this point, interacting with the server, the HTML5 end with Ajax, can be used in the background aspx, or ashx, or ASMX, which corresponds to the normal ASPX page or the general Handler ashx page, or directly write WebService services. Hope to help everyone.

Mobile development HTML5, will be the mainstream, meet it together!

C # ASP. NET PhoneGap HTML5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.