I am struggling with a problem about automatic AJAX load of page. I have normal static page, where is a link. After click on this link I will call an AJAX request for loading a data.
This works me. I try now to add next functionality - I would like after load a normal static page to load that AJAX data automatically - is possible to do somehow?
I tried it to do whole afternoon, but I still don't know, how to do it...
So, I will very grateful for every hints, how to do it... Thank you so much.
Make your Ajax call in your jQuery ready function, e.g.:
<script>
$(function() {
$.ajax(...);
});
</script>
Related
I have Easy Fancybox with Ajax Load More + Next Page Addon (Same company). My issue is Easy Fancybox does not recognize content after the first page break and so it loads images without the light box.
Example: http://boyonamountain.com/?p=118&preview=1&_ppp=fe18270bb4
Now, I have been researching for hours now and it seems there are some work arounds with requiring a call back.
Problem is, I am a designer and this is my personal site so I only have HTML/CSS knowledge.
I found this: how to bind fancybox to dynamic added element?
tried adding the code from that to the repeat template part of Ajax Load More,
I also tried to add it to the function.php, all to no avail.
Would someone be willing to help me trouble shoot this? Thank you all so much!
I'm also using easy fancybox and you just have to bind an event to the post-load easy fancy box handler;
I chose the focusin event that really happens after the loading of my completed form :
<script type="text/javascript">
jQuery( document ).on( 'focusin', easy_fancybox_handler );
</script>
You have to tell the plugin that content is loaded, choosing the good event.
I have a jquerymobile ajax based web app. not using ajax is no option.
On one page a new script is inserted by <script url="../script.js"></script>
Now i would like to load that script, after the page is loaded by ajax. Unfortunately it does not happen. I tried for example:
$(document).live( 'pageinit',function(event)
CODE HERE
{});
But it does not work. As well as
$(document).bind('pageinit', function()
Any ideas how i can manage to load the function after the page is loaded by ajax??
Found the solution with help of "OMAR". I put the function inside the page div. But the link is not working, so i put the code itself into the top of the div. now it is working. not the best solution, but it is working.
I'm trying to load a chart from the google charts api. For the most part it is working as planned. The issue comes on the initial page load. If I navigate from another part of my site to the page (using router) it loads fine. However, if I hit the refresh button on the page the chart does not load until I leave and re-enter the page.
I have this in my main.html header:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
and in my template.templatename.rendered AND template.templatename.created I have
google.load("visualization", "1", {'callback':function() {},packages:["corechart"]});
google.setOnLoadCallback(drawChart);
Deps.autorun(function () {
drawChart()
})
Where drawChart() calls the google visualization commands. I do understand I'm probably calling some repetitive code currently, but all of this is in an effort to get the page to load when I hit refresh.
I appreciate any help.
Please let me know if there is any more info needed. Thanks.
Placing the Google jsapi file in the main.html header will cause the browser to run the Javascript after the DOM is completely loaded, which is too late for your purposes.
Meteor is calling your google.load code before the DOM is completely rendered, so when you hit refresh page, the jsapi file is undefined when Meteor calls google.load.
However, if you navigate away and then back, the DOM has already been loaded once, so the chart will be rendered correctly.
To solve this, I would suggest just saving a local version of http://www.google.com/jsapi in your client folder.
Thus, Meteor will load it before it calls the google.load code.
I am using a ajax call to update page content and update the URL accordingly. I have share buttons on the page and when I want to share the whole page I only receive the previous loaded URL.
So as an example -
http://localhost/labs/category/best-of-the-best-campaign/
is my current loaded URL. When I do a Ajax call
http://localhost/labs/tag/ecommerce/?catid=2
This is the new URL. But when I share the page I still get the previous loaded URL. which is
http://localhost/labs/category/best-of-the-best-campaign
Could anyone point to me what might be going wrong?
<?php echo $url="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";?>
This is what I'm using to get the current URL of the page. I have a doubt that it might be due to the server request but I am not entirely sure about it and how I might change it.
Any help will be greatly appreciated.
Thanks
I think you should reinitialize the $url variable after ajax call
You can write php code in your ajax sucess function like,
<script>
......// your code
success:function()
{
// your code
<?php
$url="http://localhost/labs/tag/ecommerce/?catid=2";
and use it.
?>
}
......// your code
</script>
Why don't you use location.href to get the url of the current page in JavaScript?
How do I get data from the database, without refreshing the page?
I dont even know where to start...
In Rails you will need to implement a page that pulls data from the DB and shows the data in whatever format you prefer, plaintext/json/xml. There's no asynchronous stuff in this part.
Ajax will be happening in frontend, the javascript part, that asynchronous connects to the webpage that you made above. jQuery's $.ajax will save you a lot of time.
You'll need to make your AJAX call from either an onload.js or a page specific js file (example.js). You'll then need to run a $.get or $.post call to the URL of the data.
Here is a pretty detailed tutorial: http://www.tutorialspoint.com/ruby-on-rails/rails-and-ajax.htm