I'm creating a mobile app with jQuery Mobile and i've a little problem. I want to create a list with some content from the database wich I get from an ajax post.
The markup looks like this:
<div data-role="page">
<div data-role="header">
<h1>Facturen</h1>
</div><!-- /header -->
<div data-role="content">
<ul data-role="listview" data-inset="true" id="Invoices">
<div id="invoiceList"></div>
</ul>
</div><!-- /content -->
<div data-role="footer">
<h4>Page Footer</h4>
</div><!-- /footer -->
This is the jQuery:
$.ajax({
type: "POST",
url: "invoices/index.php",
data: '',
complete: function(data)
{
$('#invoiceList').html(data.responseText);
}
});
Well, I put the results of the query between but in some way the css doesnt work of the list doesnt work.
if I trie this it worked fine:
<ul data-role="listview" data-inset="true" id="Invoices">
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
Somebody knows how to fix this?
Thanks in advance!
In jQuery Mobile, whenever you update elements there is usually a follow-up step where you trigger an action upon it. For example, when you add new things into an unsorted list, you need to call
$('#invoiceList').listview('refresh');
This would go immediately after adding these elements into your UL inside the complete: callback.
There are various other things you could try as well if this doesn't generate the behavior you're looking for. For example, you might need to execute the .append() operation instead of using .html(). I've seen that sort of usage more frequently in these sorts of circumstances.
Try adding to the ul element you id as class invoiceList, because you are appending the li elements in the div element and formatting will not work:
<ul data-role="listview" data-inset="true" id="Invoices" class="invoiceList">
</ul>
<script>
$.ajax({
type: "POST",
url: "invoices/index.php",
data: '',
complete: function(data)
{
$('.invoiceList').html(data.responseText);
}
});
</script>
Related
I am writing an admin dashboard in PHP at the moment.
To simplify things, as far as I think it simplifies, the page I structured has the typical areas Header, Aside with menu and MainContent page. The main content page should change when I click a different page in the aside menu.
So I created the page index.php which will hold the whole framework of the page.
<?php include('../includes/overall/overallHeader.php'); ?>
<section class="content-header">
<h1>Einsatzliste</h1>
</section>
<script type="text/javascript">
$('#pageIncidents').click(function(){
$('#mainContent').load('incidents.php');
});
</script>
<section class="content">
<div id="mainContent">
</div>
</section>
<?php include('../includes/overall/overallFooter.php'); ?>
Within this I created the section content, and gave the div inside the id mainContent. My idea was to load different subpages into this div, when I click a menu item in the aside menu:
aside menu
<div class="navbar-default sidebar" role="navigation">
<div class="sidebar-nav navbar-collapse">
<ul class="nav in" id="side-menu">
<li><div id="pageIncidents">Einsatzliste</div></li>
<li>Testseite 1</li>
</ul>
</div>
</div>
There I put the link inside a div with a unique ID which I want to use in jQuery to load the specific contents.
jQuery script
<script type="text/javascript">
$('#pageIncidents').click(function(){
$('#mainContent').load('incidents.php');
});
</script>
The script is supposed to load the page incidents.php into the div mainContent in the index.php page.
It totally does not work... Do you have a hint where to look for? I think the logic seems right I guess. Could it be a problem, that the id "pageIncidents" is not directly visible in the code but included by the php include overallHeader at the top of the page?
You can try doing it with ajax and make up the ajax response in html (string), onclick start ajax request.
$(document).on("click", ".delete-asset", function() {
var link = $(this).attr('[data-page]');
$.ajax({
type:'GET',
url:'http://www.example.com/index.php',
dataType: "json",
data: {
action: 'incidents',
data: { 'incidents': 'incidents' }
},
success:function(data) {
$('#mainContent').html("[your data]");
}
});
});
My code works correctly for showing database data .but i want to use infinite scroll for large data show response time.But I have no Idea how to use infinite scroll with my this code also which plugin use.
<script>
function getfilter(str){
if (str==""){
document.getElementById("result").innerHTML="";
return;
}
$.ajax({
url: "Views/pfolioresult.php?q="+str,
type: "GET",
// data: serializedData,
success: function ( responseText ) {
$("#result").html(responseText);
}
});
}
</script>
<div class="sprocket-mosaic-header">
<div class="sprocket-mosaic-filter">
<ul>
<li class="all active" data-mosaic-filterby="all" onclick="getfilter(this.id)" id="all" >All</li>
<li class="android" data-mosaic-filterby="android" onclick="getfilter(this.id)" id="android" >Android</li>
<li class="iOS" data-mosaic-filterby="iOS" onclick="getfilter(this.id)" id="ios" >IOS</li>
</ul>
</div>
<div class="clear"></div>
</div>
<div id="result">
ok
</div>
you can use http://infiniteajaxscroll.com/ or http://jscroll.com/. this will help you.
In my code which is using bootstrap, I got a problem.
I am using JS code shown as below.
$( "li:eq(1)" ).click(function() {
$.get("./test.php")
.done(function(data) {
$('#middle').html(data);
});
It is to control the div.
<div class="container" id=header-nav>
<a class="brand" href="index.php"></a>
<div class="nav-collapse collapse" >
<ul class="nav">
<li class="active">Home</li>
<li>test</li>
.......
<div class="container" id="middle"> </div>
When I click the test button, the link will change to test.php# but nothing change. Click again, it can load into the test.php.
The problem is the link is test.php, the code not work. when test.php# , it work. And I would like to know why.
Thanks a lot.
The problem is because you have attached the handler to the li element, but the a element is clicked, and then transfers the page. Try this instead:
$("li:eq(1) a").click(function(e) {
e.preventDefault();
$.get("./test.php")
.done(function(data) {
$('#middle').html(data);
});
});
The preventDefault() stops the default behaviour of the link, meaning your AJAX request gets executed as required.
since you want to use $.get (AJAX), you don't have to give the url to <a> element inside your <li> element,
you have to give the attribute href inside <a> element this value: javascript:void(0) Or #,
your html code would be:
<div class="container" id=header-nav>
<a class="brand" href="index.php"></a>
<div class="nav-collapse collapse" >
<ul class="nav">
<li class="active">Home</li>
<li>test</li>
.......
<div class="container" id="middle"> </div>
or you have to prevent default action for the element to prevent reloading url by adding:
event.preventDefault() in you onclick event and your js code would be:
$( "li:eq(1)" ).click(function(e) {
event.preventDefault();
$.get("./test.php")
.done(function(data) {
$('#middle').html(data);
});
I am trying to build a menu for my website and using Smarty to display the pages. When user click on the Logout option the JQuery send an Ajax call to index.php script which contain the code for Smarty to display the page but it is not displaying it. It was working fine before I added the menu. There is no error in the firebug too. Can someone put me in the right direction.
Here is PHP code
if (isset($_POST['menu_index']))
{
if ($_POST['menu_index'] == 'Logout')
{
$smarty->display("login.tpl");
exit;
}
}
Here is JQuery code
$('ul li a').on('click', function() {
var menuItemIndex = $(this).data('val');
console.log(menuItemIndex);
$.ajax({
url: 'index.php',
type: 'POST',
data: {
'menu_index': menuItemIndex
},
dataType: 'json',
success: function(response) {
alert('success');
},
error: function(errorMsg) {
alert('failed');
}
});
});
Here is HTML Code
<form name="mainmenu" id="mainmenu">
<div id='content'>
<div id='jqxMenu'>
<ul>
<li>Maintanence
<ul style='width: 180px;'>
<li>Add Category</li>
<li>Add Sub-category</li>
</ul>
</li>
<li>Process Order
<ul style='width: 180px;'>
<li>Ship Order</li>
<li>Change Order Status</li>
</ul>
</li>
<li>Reports
<ul style='width: 180x;'>
<li>Orders by station</li>
<li>Orders by date</li>
<li>Pending Orders</li>
</ul>
</li>
<li>Logout</li>
</ul>
</div>
</div>
</form>
Hi I think you don't understand how Smarty works, but I can tell you that you don't have any template in html code which is very important for this kind of programming.
You need to make template for menu and call it menu.tpl -> then include it on index.tpl ...
For more informations take a look www.smarty.net
i have succeeded in listing my data from mysql database
in JQM.
i want to link the list item to its details.
Therefore when there is a click on a list, a new page with the data from the list is displayed.
I dont know how to do it
Heres what i have now : but the link i have isnt working, guess i am missing something.
heres the link on js fiddle http://jsfiddle.net/8WU39/16/
<script type= text/javascript>
$('#seyzListPage').live('pageshow', function(){
$.ajax({
url: "data.php",
dataType: 'json',
success: function(json_results){
listItems = $('#seyzList').find('ul');
$.each(json_results.rows, function(key) {
html = '<li <h3><a href="index1.html?id=' + [json_results.rows[key].airp_id] +'"rel="external">'+json_results.rows[key].airport_code+'</h3>';
html += '<p><br> Aiport name: '+json_results.rows[key].airport_name+'</p></a></li>';
listItems.append(html);
});
// Need to refresh list after AJAX call
$('#seyzList ul').listview('refresh');
$.mobile.pageLoading(true);
}
});
});
</script>
<div data-role="page" id="seyzListPage">
<div data-role="header" id="header">
<h1>Airports</h1>
</div>
<div data-role="content" id="seyzList">
<ul data-role="listview" data-inset="true" data-filter="true"></ul>
</div>
<div data-role="footer" data-postion="fixed">
<h3>Footer</h3>
</div>
</div>
What do i do to get the list linked to its data on another html page.
I had a very similar problem and found a fix with a simple plugin. It's called jqm.page.params.js and can be found here. Implementation was very easy. Added the plugin file to my root directory and then included it at the bottom of my index.html page.
In your js file, you then just want to place
if ($.mobile.pageData && $.mobile.pageData.color){
var color = $.mobile.pageData.color;
}
at the top of your beforepageshow event to capture the variables tacked on to the link. Replace 'color' with the variables you are looking for.