Java (ajax) communicate with external PHP (Cordova in VS) -


i'm creating cross-platform application in cordova using visual studio. need communicate external web-server, processing mssql server.

in client side have index.html file , uses external javascript file index.js.

on server-side have several php pages. every single 1 has different purpose.

index.html:

<form id="sendmsg" method="post" action="http://www.somesite.com/.../processingmsg.php" enctype="multipart/form-data">             <p class="darkbg">* verplichte velden</p>             <div class="form-group">                 <label class="darkbg">naam</label>                 <input class="form-control" onkeyup="lengtecheck()" type="text" name="naam" id="naam" />             </div>             <div class="form-group">                 <label class="darkbg">leeftijd</label>                 <input class="form-control" onkeyup="lengtecheck()" type="text" name="leeftijd" id="leeftijd" />             </div>             <div class="form-group">                 <label class="darkbg">telefoon</label>                 <input class="form-control" onkeyup="lengtecheck()" type="text" name="telefoon" id="telefoon" />             </div>             <div class="form-group">                 <label class="darkbg">email</label>                 <input class="form-control" onkeyup="lengtecheck()" type="email" name="email" id="email" />             </div>             <div class="form-group">                 <label class="darkbg">*es code</label>                 <input class="form-control" onkeyup="lengtecheck()" type="text" name="escode" id="escode" required />             </div>             <div class="form-group">                 <label class="darkbg">*bericht</label>                 <p class="darkbg" id="tekens">0/100</p>                 <textarea class="form-control" onkeyup="lengtecheck()" rows="7" id="msg" name="msg" cols="20" placeholder="typ hier uw bericht..." maxlength="100" required></textarea>             </div>             <input class="btn btn-primary" type="submit" value="send" id="send">             <input action="action" class="btn btn-danger" type="button" onclick="window.history.back();" value="back">         </form> 

how can make when user clicks send button, processingmsg.php process , on success, trigger javascript function on client side?

additional question: can return set of results (e.g table, dropdown values, etc.) this?

don't rely on browser's default <form action="..."> handling this. instead use ajax (xhr). html5rocks has great example: https://www.html5rocks.com/en/tutorials/file/xhr2/#toc-send-formdata

then, can parse response needed , update dom necessary. suggest returning json, since can use json.parse(response) useful javascript object that's easy work with.

tip: use https , ssl/tls. , don't forget whitelist host , set content-security-policy meta tag appropriately.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -