javascript - Add new data from HTML form in external XML file using Ajax and PHP -


i stuck , unsure. webpage displaying table, based on existing xml file.

i want give option of adding new line in table. read cannot use js write on external xml file, have use php script.

the problem i'm not sure implementation logic. here point:

  1. the page displayed empty table (done).
  2. javascript fills table xml file data (done).
  3. the user fills html form fields.
  4. when user press 'submit' button, javascript captures fields content , send them php script (post method) (not developed yet).
  5. php catches post data, append them xml file (not developed yet).
  6. when done, javascript refresh table using freshly updated xml file (not developed yet).

am doing right? thank help!

--

edit

thank our help. unfortunately, cannot make thing working. form value cannot retrieved (penseigne undefined)

here html form (extract)

<form class="form-inline" name="newlineform"> <input type="text" class="input-small" placeholder="enseigne" name="enseigne"/> <button type="submit" class="btn btn-primary" id="zou">zou!</button> </form> 

here js functions (extracts)

$('#zou').on('click', function(){ exportline(); $('.form-inline').hide(); $('#ajouter').fadein(); return false });  function exportline(){ var penseigne = $('#enseigne').val(); var xmlhttp; xmlhttp=new xmlhttprequest(); xmlhttp.onreadystatechange=function(){ if (xmlhttp.readystate==4 && xmlhttp.status==200){ loaddata(); }} xmlhttp.open("post","php/form-process.php",true); xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); xmlhttp.send("fenseigne="+penseigne); } 

and php thing

<?php $enseigne = htmlentities($_post['fenseigne']); $lignes = simplexml_load_file('../list.xml'); $lignes->ligne->addchild("enseigne",$enseigne); ?> 

could please give me hand again?

i think general process sound. instead of doing straight post-form, use javascript capture form , send it. allows set javascript method wait the php return status code before triggering update.

see bit here sending request asynchronously , using handler deal results.

http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -