Note that there are some explanatory texts on larger screens.

plurals
  1. POThe requested URL was not found when calling an ajax function
    primarykey
    data
    text
    <p>//I want to insert a text in the database (MySql) by calling a js function then another js //scripts retrieves the data from the database and displays it in a div on my html page //from //where i posted the text .... </p> <p>//HTML from where i submit the text to be saved in the database </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;div id = "change"&gt;Naruto&lt;/div&gt; &lt;form id = "foo" action = "update()"&gt; &lt;input type = "text" name = "text" id = "text"/&gt; &lt;input type = "submit" value = "change" &gt;&lt;/input&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>// the function that is called when i click the button </p> <pre><code>&lt;script&gt; function update() { $("#foo").submit(function(event) { /* Stop form from submitting normally */ event.preventDefault(); /* Clear result div*/ $("#result").html(''); /* Get some values from elements on the page: */ var values = $(this).serialize(); /* Send the data using post and put the results in a div */ $.ajax({ url: "acition.php", type: "post", data: values, success: function(){ alert("success"); $("#result").html('Submitted successfully'); }, error:function(){ alert("failure"); $("#result").html('There is error while submit'); } }); }); } &lt;/script&gt; </code></pre> <p>//the php file that actually updates the data </p> <pre><code>&lt;?php mysql_connect("localhost","root","") or die ("CANNOT CONNECT TO THE DATABASE".mysql_error()); mysql_select_db("ajax_database") or die ("CANNOT CONNECT TO THE DATABASE"); $text = $_POST['text']; $sql = "insert into news(statement)values('$text')"; mysql_query($sql); ?&gt; &lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; </code></pre> <p>// the script that gets the data from a different page to show it to the html div</p> <pre><code>&lt;script&gt; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("change").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET","getdata.php",true); xmlhttp.send(); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>// the php file that selects the data to be retrieved from the database // getdata.php</p> <pre><code>&lt;?php mysql_connect("localhost","root","") or die ("CANNOT CONNECT TO THE DATABASE".mysql_error()); mysql_select_db("ajax_database") or die ("CANNOT CONNECT TO THE DATABASE"); $sql = "select * from news"; $result = mysql_query($sql); while ($rows = mysql_fetch_array($result)) { echo $rows[0]; } mysql_close(); ?&gt; </code></pre> <p>//basically just like we update the status on facebook .... i am doing the same thing .... //without refreshing the whole page it refreshes the part of the html page where the new //updated text will be shown //<code>enter code here</code>thanks i am really in a mess right now .... please help me out .... i am //new to ajax ...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload