Appcan Mas Interface Ajax

Source: Internet
Author: User

1. Open Appcan IDE, file → New →mas service

2. New MAS Project

3. New MAS interface, access address http://mobile.163.com/special/chuangye/

4, modify the If.js under the If_cytznews

1varMeap=require ("MEAP");
2
3functionRun (Param, Robot, Request, Response, IF)
4{
5
6varoption={
7Method: "GET",
8URL: "http://mobile.163.com/special/chuangye/",
9Cookie: "True",
TenCharset: "gb2312"
One};
A
-MEAP. Ajax. Runner (option,function(Err,res,data) {
-if(!err)
the{
-//Add your normal handling code
-MEAP. PARSER. Runner ("HTML", Res.text,function(Err,dom) {
-if(!err && DOM)
+{
-//ADD your DOM handling code
+varResult=[];
AvarUl=dom.getelementsbytagname (' ul ');
atvarLi=ul[0].childnodes;
-varTitle= ', link= ', date= ';
- varobj={};
-varAtag= ";
- for(vari = 0; i<li.length;i++) {
- //datespan=li[0].getelementsbytagname (' span ') [0];
inDate=li[i].childnodes[0].innerhtml.replace (/\ (/, "). Replace (/\)/, ');
-ATAG=LI[I].CHILDNODES[1];
toLink=atag.href;
+title=atag.innerhtml;
-//Console.log (link,title);
theobj={
*Title:title,
$Href:link,
Panax NotoginsengDate:date
-}
theResult.push (obj);
+}
A//Console.log (li.length);
the}
+//Response.setheader ("Content-type", "text/html; Charset=utf-8 ");
-Response.setheader ("Content-type", "Application/json; Charset=utf-8 ");
$Response.End (json.stringify (result));
$//Response.End (data);
-});
-}
the Else
-{
Wuyi//ADD Your exception handling code
the}
-
Wu},robot,function(DES) {
-//Add your Web HTML pretreatment code to decrease DOM parsing time.
AboutvarStart=des.indexof (' <div class= ' content > ') + (' <div class= ' content ' > '). length;
$varEnd=des.indexof (' <div class= ' listpages ' > ');
-returnDes.substring (start,end). Replace (/<\/div>$/, ")
-. replace (/<span class=\ "dotline\" ><\/span>/ig, ')
-. replace (/<\/ul>\n\n<ul class=\ "list_f14d\" >/ig, ')
A. replace (/\n/g, ");
+});
the}
-
$Exports. Runner = run;

5. Right-click Mas.js and select "Run".

6. Enter Http://127.0.0.1:8082/xm150102/cytznews in the browser address bar

The final result is as follows:

Appcan Mas Interface Ajax

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.