I have a website where I am switching from addThis to addToAny for social sharing buttons. The problem is that the share buttons are contained in content that is loaded dynamically with jquery Waypoints infinite scroll feature (which uses Ajax). When the page first loads (so no Ajax called yet) everything works great, but when a user scrolls and more content is added that contain the share buttons, the new buttons don't work in that they don't show the share options on hover or click.
There are supposedly fixes for this if using templates from the likes of Drupal or Wordpress, but my site is not built using any of these templates. This was also a known issue with addThis, and to get around the problem you simply need to add 'addthis.toolbox('.addthis_toolbox')' into the success portion of the ajax call and things would work.
I haven't had any success getting addToAny to work after ajax returns. They have something that looked promising: a2a.init('page'), but that doesn't work. Has anyone had this problem and have any suggestions on how to fix it? Thanks!
If there so many share button on one page you can call this after ajax success:
$(".a2a_dd").each(function() {
a2a.init('page');
});
Or if there only one share button, you can use this after ajax success:
a2a.init('page');
If want to know more details go through this document
According to the AddToAny API (https://www.addtoany.com/buttons/api/), you should use a2a.init_all(); if you are loading a number of new share button sets at once via AJAX.
Using a2a.init('page'); only initializes the last uninitialized buttons instance on the page. That might be fine for you, depending on how many new buttons that you load at a time.
Example: you have a blog site that loads new posts when the user scrolls to the end of the page. If you are only loading one new set of share buttons for the new content, a2a.init('page'); should work. If instead, you are loading a few new posts at a time, that each get their own set of share buttons, you will want to use a2a.init_all();
Hope this helps someone!
I am using this plugin for adding arrow key navigation to a website
Works great! However, sometimes my links are updated via AJAX and then the highlighting disappears. So I started re-initializing the plugin when my links were updated. I noticed this solved the problem, however now I had multiple copies of the plugin running, thus highlighting multiple buttons at once.
I know there isn't a 'built in' destory method in Jquery, but does anyone have any ideas on how to re-initialize a plugin or at least get rid of the old instance running.
You can see the source code of the plugin on GitHub
The plugin code is simple and I believe what I am trying to achieve is simple as well. Thanks!
The plugin you are using has an update function, call that function as soon as you get the ajax result back.
for example
var $keyNav = $('#navigation a').keynav();
and on ajax success
$keyNav.update();
I haven't tested this code but I think it will work.
I'm using Yii framework and have small problem.
Then I include to the partial CHtml::ajaxLink, link stopping work as ajax, standart click is raised and performs redirect to another page.
Can anyone help me? Thanks.
Just a supposition, but turn processOutput on when using partialRender with javascript. It's the fourth parameter when calling renderPartial:
$this->renderPartial('_view',array(params...),false,true)
ProcessOutput allows you to also load javascript when rendering with asynchronous calls or other stuff.
Turn firebug on and check for js errors. If there are any, post them here
There was something wrong with yii CHtml::ajax implementation, and it caused me similar bug to yours.
Maybe you not finishing document right?
try with:
Yii::app()->end();
And check differences in generated HTML between old version (which worked) and this one.
Maybe some js lib not included?
What is the official line on how to make sure a razor view is rendered as latest? At the moment it appears I am getting a cached version.
I have a view, that renders a partial and this partial renders a template.
Save, compile, iis reset:
Same old view!
Stop it now!
Let me give u an example
#Html.EditorForModel("~/Views/Shared/EditorTemplates/Object.ascx")
Renders Object.ascx
Remove that line renders nothing (good)
Then adding
#Html.EditorForModel("~/Views/Shared/EditorTemplates/Huh.cshtml")
Renders Object.ascx
=Insanity.
Did you try Ctrl+F5 in your browser? Maybe the html was cached on the client. Also if you are using the [OutputCache] attribute to cache it downstream this could happen.
UPDATE:
After you have posted your code you seem to have overriden the ~/Views/Shared/EditorTemplates/Object.ascx default template. Then you replace this line by:
#Html.EditorForModel("~/Views/Shared/EditorTemplates/Huh.cshtml")
but depending on the model used in Huh.cshtml Object.ascx could still be rendered for some properties.
Found it: it has to be called Object.cshtml and no other control called "Object" can live in that folder (e.g. Object.ascx).
After upgrading my ASP MVC from 3 Preview to 3 Beta I see strange behaviour in my Ajax forms.
#using(Ajax.BeginForm("New", new AjaxOptions() {OnSuccess = "onAjaxSuccess", OnFailure = "onAjaxFailure", OnBegin = "onAjaxBegin", HttpMethod = "Post"})) {}
<form action="/Order/New" data-ajax="true" data-ajax-begin="onAjaxBegin" data-ajax-failure="onAjaxFailure" data-ajax-method="Post" data-ajax-success="onAjaxSuccess" method="post"></form>
I have placed an alert inside my function onAjaxBegin and it is beeing fired twice, each time i click on my submit button.
Anyone else seen this behaviour? I have not changed anything in the code after upgrading, and it worked perfectly before the upgrade.
I had the same problem, and i found the solution: I included the "jquery.unobtrusive-ajax.min.js"-Script twice :-)
Look at the generated HTML. In ASP.NET MVC 3 Beta there's new support for unobtrusive jquery based ajax and all the Ajax helpers use jquery now. Maybe there's something left with MS Ajax which causes the double call. Make sure you remove all the inclusions of MSAjax scripts from the page. Also why using Ajax.BeginForm when you could simply use Html.BeginForm with unobtrusive jquery?
The duplicated jquery.unobtrusive-ajax.min.js can also happened if your controller returns a View() instead of PartialView().
I had the same problem using a AJAX.BeginForm call that is loaded dynamically using $.load()
I solved it by removing the extra include of jquery.unobtrusive-ajax.min.js on the loaded form. That's the key!
one small tip all the time before you using .live(), do .die() :)
this will kill all the java scripts attached to this event and will create a new one.
example:
$(function() {
$('#MyInfoForm').die();
$("#MyInfoForm").live('submit', function(e) {
//some code
e.preventDefault();
});
});
Just for future reference for those using ASP.NET MVC; "~/Scripts/jquery.unobtrusive*" does also include "~/Scripts/jquery.unobtrusive-ajax.js".
So if your BundleConfig looks like this;
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.unobtrusive-ajax.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
It will result in submitting an Ajax form twice. Removing either "~/Scripts/jquery.unobtrusive*" or "~/Scripts/jquery.unobtrusive-ajax.js" will fix the problem.
Just posting this because it is easy to overlook "~/Scripts/jquery.unobtrusive*" when searching for unobtrusive-ajax.
You can use bind instead of live in jquery.unobtrusive-ajax.min.js~~~ This is very important.Because live event will call the previous events every time but bind only calls the current event.
Moving jquery.unobtrusive-ajax.js outside partial-view solved the issue in my case.
I had the same problem. I had a login partial view in master page that included jquery.unobtrusive-ajax.min.js. I also had this file included in my view. So I removed one and the problem is solved now.
I also had this exact problem and for a very different reason. I had included the script reference to the jquery.unobtrusive-ajax.min.js within the div that got updated. Moving it outside the div fixed it.
This might be helpful for someone having a scenario similar to what I have:
On my page, the edit form opens a partial view inside a Kendo UI modal pop-up window, which loads the code of the form dynamically, including jquery.unobtrusive-ajax.js. With this setting, - which can relate to any pop-up such as that of jQuery UI and not just Kendo UI - the behavior of form submission is as follows:
The first time the pop-up window is opened, the form submission causes a single call to the controller (server-side) code. So far so good. However, for the second time that the window is opened (without closing the container page), the form submission calls the controller 2 times. Subsequently, each re-opening of the pop-up window, causes an additional loading of the jquery.unobtrusive-ajax.js code, which in turn causes an additional unwanted call to the controller at each single submission of the form.
In order to fix the problem, I moved the inclusion of jquery.unobtrusive-ajax.js from the partial view of the pop-up window into the main page. However this made the client-side validation stop working, and to fix that, I used the solution provided in here:
client side validation with dynamically added field which links to this blog post:
http://xhalent.wordpress.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/
I found out the solution, just remove all jquery.unobtrusive-ajax.js references, since you are using the Ajax.BeginForm it will use the ajax normally.
So it doesn't has to disable the ajax.
this is old but I found something really stupid that is easy to overlook.
Our form also had the following attached to it:
$(document).ready(function () {
$('#submit-button').on('click', function (e) {
....
}
});
Obviously the .NET code handles this itself.