Создайте новый файл index.php со следующим содержанием:
<head> <script language="javascript" src="ajax_framework.js"></script> </head> <body> <div id="myText">This is my text to modify with edit in place</div> <script> new Ajax.InPlaceEditor($('myText'), 'javascript:saveText("myText")', { ajaxOptions: {method: 'get'} }); </script> </body>
/* XMLHTTPRequest Enable */ function createObject() { var request_type; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ request_type = new ActiveXObject("Microsoft.XMLHTTP"); } else { request_type = new XMLHttpRequest(); } return request_type; } var http = createObject(); /* -------------------------- */ /* SAVE TEXT */ /* -------------------------- */ var nocache = 0; var text = ''; function saveText(textId){ textId_n = encodeURI(document.getElementById('textId').value); textIDGlobal = textId_n; nocache = Math.random(); http.open('get', 'save_text.php?newText='+textId_n+'&nocache = '+nocache); http.onreadystatechange = saveTextReply; http.send(null); } function saveTextReply(){ if(http.readyState == 4){ var response = http.responseText; document.getElementById(textIDGlobal).innerHTML = response; }
<!-- Include Database connections info. --> <?php include('config.php'); if(isset($_GET['newText'])){ $newText= $_GET['newText']; $insertText_sql = 'INSERT INTO MYTABLE (newText) VALUES('. $newText .')'; $insertText= mysql_query($insertText_sql) or die(mysql_error()); echo $newText; } else { echo 'Error! Please fill all fileds!'; } ?>
<?php // Connection's Parameters $db_host="localhost"; $db_name="database_name"; $username="database_username"; $password="database_password"; $db_con=mysql_connect($db_host,$username,$password); $connection_string=mysql_select_db($db_name); // Connection mysql_connect($db_host,$username,$password); mysql_select_db($db_name); ?>
© Copyright 2008-2012 by KDG