- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could someone please point me to some sample code or a tutorial for uploading form data plus an image to a php server, using JSON and xmlhttp commands.
I'm quite new to this but have now managed to get form data fields uploaded to a server and written to a database. Have also managed to retrieve data from database down to my App...including an image in the JSON array.
I've found code to upload an image on it's own ...BUT I'm really struggling to find how to upload a form of data PLUS an image.....(so that they can be written to a database record together.
JS code so far is as follows;
<script type="text/javascript"> function loadData() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var arr = JSON.parse(xmlhttp.responseText); var i = 0; var out = "<table>"; for(i = 0; i < arr.length; i++) { out += "<tr><td>" + arr.Id + "</td><td>" + arr.UserName + "</td><td>" + arr.Title + "</td></td>" + arr.Details + "</td><td>" + arr.Date + "</td><td>" + arr.Graphic + "</td></tr>"; alert(arr.Graphic); document.getElementById("imageid").src=arr.Graphic; } out += "</table>"; document.getElementById("id01").innerHTML = out; } } xmlhttp.open("GET","http://xxxx.co.uk/SBGetPosts.php?posts=all", false); xmlhttp.send(); } </script> <script> function sendData() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { alert("All Gone"); } } var postdata = '{"SBP_UserName": "Phil", "SBP_Title": "Title1"}'; xmlhttp.open("POST","http://xxxx.co.uk/SBPostPost.php", false); xmlhttp.setRequestHeader("Content-type","application/json"); xmlhttp.send(postdata); } </script>
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I recommend you explore the general HTML5 programming sites on the web (such as W3C Schools, StackOverflow and HTML5 Rocks). We are only staffed to provide you with Cordova/XDK-specific issues, we don't have the resources to answer general HTML5 questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok thanks, no problem Paul - have looked around and can find upload of data and upload of graphics, but not combining.
Will keep trawling.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page