Send android local HTML forms via ajax to remote php server -


is there way send android local html forms via ajax remote php server? (local means files in device) scenario this: in app, have html files in android device , loaded in webview, have javascript file in device. want send html forms data remote server. in current situation, not sending data, i've check javascript , php , code fine, , it's working on ios version of app. i've tried other workarounds , i've observed that, when load html file in webview using local files (e.g. webview.loadurl("file://"+ environment.getexternalstoragedirectory()+"/android_asset/list.html"), android looking other related files (e.g. formsprocessor.php) locally, though in javascript/ajax necessary arguments in it's functions supplied properly. errors i've encountered are: filenotfound: content://packagename.com/formsprocessor.php & unknown chronium error: -6. there way or best way this?

thanks, clint.

this solve problem: used javascripthandler, , in javascript call function handler. basically, android handled upload of data server using httppost. here's codes;

the handler:

final class ijavascripthandler{      ijavascripthandler(){}       public void sendjsontoandroid(string text){             if(!config.canconnect((connectivitymanager) getsystemservice(connectivity_service), home) && dialognoconnflag == false)                 {                     dialognoconnflag = true;                     config.notificationmsg(config.errornoconn,home, config.title1 + " " + config.title6);                     return;                 }                 try {                     log.v("sendtoserver","send json server");                     string url = "";                     jsonobject json_data = new jsonobject(text);                     jsonarray names= json_data.names();                     jsonarray values = json_data.tojsonarray(names);                     list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();                     for(int = 0 ; < values.length(); i++){                         log.v("good",names.getstring(i).tostring());                         if(names.getstring(i).equals("url")) {                             url = json_data.getstring(names.getstring(i)).tostring();                         }                         namevaluepairs.add(new basicnamevaluepair( names.getstring(i).tostring(),  json_data.getstring(names.getstring(i)).tostring()));                      }                     config.uploadtoserver(namevaluepairs, url);                 }                  catch (jsonexception e)                  {                      config.notificationmsg(config.errormsg + e.getmessage(), (activity) home, config.title1 + " " + config.title6);                 }            }      } 

the httppost:

    public static string uploadtoserver(list<namevaluepair> namevaluepairs, string url){     if(session.isordinaryhost)     {         httpclient = new defaulthttpclient();     }     else     {         httpclient = new myhttpclient().getnewhttpclient();         ((abstracthttpclient) httpclient).getcredentialsprovider().setcredentials(               new authscope(session.siteip, 443),                new usernamepasswordcredentials(session.siteusername, session.sitepassword));     }     httppost = new httppost(url);       try      {         httppost.setentity(new urlencodedformentity(namevaluepairs));          // execute http post request         httpresponse response = httpclient.execute(httppost);         httpentity entity = response.getentity();           entityutils.tostring(entity);       }     catch (clientprotocolexception e)      {          return e.getmessage();     }      catch (ioexception e)      {          return e.getmessage();     }      return null; } 

the javascript:

function checkcompleterecords() { db.transaction(function(tx) {     tx.executesql(selectcompleteforuploadstatement, [], function(tx, result) {      dataset = result.rows;         (var = 0, item = null; < dataset.length; i++) {             item = dataset.item(i);     var = createjson(item['formname'],item['userid'],item['image1'],item['image2'],item['image3'],item['image4'],item['image5'],item['field1'],item['field2'],item['field3'],item['field4'],item['field5'],item['field6'],item['field7'],item['field8'],item['field9'],item['field10'],item['field11'],item['field12'],item['field13'],item['field14'],item['field15'],item['field16'],item['field17'],item['field18'],item['field19'],item['field20'],item['field21'],item['field22'],item['field23'],item['field24'],item['field25'],item['field26'],item['field27'],item['field28'],item['field29'],item['field30'],item['field31'],item['field32'],item['field33'],item['field34'],item['field35'],item['field36'],item['field37'],item['field38'],item['field39'],item['field40'],item['field41'],item['field42'],item['field43'],item['field44'],item['field45'],item['field46'],item['field47'],item['field48'],item['field49'],item['field50'],item['field51'],item['field52'],item['field53'],item['field54'],item['field55'],item['field56'],item['field57'],item['field58'],item['field59'],item['field60'],item['field61'],item['field62'],item['field63'],item['field64'],item['field65'],item['field66'],item['field67'],item['field68'],item['field69'],item['field70'],item['field71'],item['field72'],item['field73'],item['field74'],item['field75'],item['field76'],item['field77'],item['field78'],item['field79'],item['field80'],item['field81'],item['field82'],item['field83'],item['field84'],item['field85'],item['field86'],item['field87'],item['field88'],item['field89'],item['field90'],item['field91'],item['field92'],item['field93'],item['field94'],item['field95'],item['field96'],item['field97'],item['field98'],item['field99'],item['field100'],item['currentdatetime'],item['geolocation'],item['barcode']);                                  window.cpjs.sendjsontoandroid(a);              showstuff('sendserverbtn');             window.location = "senttoserver://app_action";     }     }); }); }    

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -