Javascript alone cannot be used to work with a database. This is done using php (or server side of your choice). Ajax is used to send a request to your php script using javascript, which in turn communicates with db. And this does not require a page refresh.
What you are trying to do can be easily achieved with ajax. Since you mentioned jquery, you can check out the $ .ajax or $ .post methods in jquery that make the process even simpler.
You need to process the form using ajax. The ajax request is sent to the php script, which will make the necessary changes to the database and send a new link (link to edit.html) in response. Once you get the answer, simply replace the current anchor with a new one.
eg.
$.post(url, formdataobject , function (resp) { $("a.youra").text('edit').attr('href', resp); });
url - where is the PHP script located
formdataobject - javascript object that will have form data as key value pairs
the third parameter is an anonymous function, also known as a callback function, because it will only be called when a response is received from the server. This is because ajax requests are asynchronous.
Inside the callback function, jquery is used to change the text inside the anchor element to edit , and the href attribute is changed to the value that appeared in the response.
$. post means we are using the post method. therefore, parameters can be accessed as elements of the $ _POST array in php. After updating db, you can simply echo exit the new link and it will be received in the response.
In addition, there are other formats in which you can get an answer, for example. xml, json.
naiquevin
source share