I am doing a website currently for my final year project using joomla and to get a better grade, I am asked to use Jquerymobile for make it easily accessible. However, I have no idea how to retrieve data from my database using mySQL and php in conjunction with Jquerymobile. Can anyone enlighten me?
You have to use Ajax. So use $.ajax
, $.post
or $.get
methods to send a request to your webserver. Then you will request your database with PDO or mysqli as usual, or you will use the joomla API as you want to use joomla.
A basic syntax is for your javascript file, let's say ajaxquery.js
. I assume you will send your request by clicking on a button whose id is clickit
(function(){
var onClickCallback(e){
//do something with DOM by handling the e object
$.ajax('yoururl',{data:{var1:"value1",var2:"value2"},type:"get"})
.success(function(xhr){
//display your data here
).fail(function(xhr){
$("#content").append($('<p class="error">An error occured</p>'));
});
}
$('#clickit').on('click',onClickCallback);
})();
This is basic question. I think you need to learn CURD with PHP and MySQL.
After that, you can use ajax to show your data:
$.post('crud.php', function(data) {
$('#result').html(data);
});
Good luck.