I am trying to make the browser to remeber the ajax updated html. So when user hit the back button, it will go back to the ajax update html. I had found the following code from stackoverflow, but I had no idea how to use it. I had tried to replace the #Mytable with my class .post-content. But it doesn't work, do I miss something. Help, appreciate.
$('#pagination').click(function(e){
var data = {
action: 'post_pagination_ajax',
AjaxFrontNonce : Child_ajax.ajaxLoadUserNonce,
};
$.ajax({
url: ajax_front_gallery.ajaxurl,
type:'POST',
data: data,
success: function(data){
$('.post-content').fadeOut().html(data).fadeIn();
$fa_spen.fadeOut();
}
});
return false;
});
// the following code found on stackoverflow, but I don't know how to replace it with my code.
if (('localStorage' in window) && window['localStorage'] !== null) {
if ('myTable' in localStorage && window.location.hash) {
$("#myTable").html(localStorage.getItem('myTable'));
}
}/*remember the previous div position*/
// Replace the search result table on load.
if (('localStorage' in window) && window['localStorage'] !== null) {
if ('myTable' in localStorage && window.location.hash) {
$("#myTable").html(localStorage.getItem('myTable'));
}
}
Related
My current code checks the country code and then changes the drop down value before submitting it for the things to refresh in right currency pricing, but I've tried things like, putting return; to stop it after running it once and moving return; on different line with no luck. I even combined the .val line with .change() thinking maybe having it on separate lines was running it multiple times and refreshing it multiple times.
Here is my code;
$.ajax({
url: "https://ipinfo.io/json",
type: "GET",
success: function(location) {
if (location.country === 'AU') {
$(".shopify-currency-form select").val("AUD").change();
} else if (location.country === 'AR') {
$(".shopify-currency-form select").val("ARS");
} else if (location.country === 'CA') {
$(".shopify-currency-form select").val("CAD");
} else if (location.country === 'US') {
$(".shopify-currency-form select").val("USD").change();
}
return;
}
} );
$('.shopify-currency-form select').on('change', function() {
$(this)
.parents('form')
.submit();
return;
});
I'm trying to hide a form only if it's on the root site, or on the specific hash https://www.example.com/#uno. My code below is causing the form is not show on all the subpages (/#dos, /#tres, etc). Can someone help me understand what is happening?
$(function(){
if (location.hash == "" || location.hash == "#uno"){
$("#form").hide();
} else {
$("#form").show();
};
}());
This is because you hide the form once, but you don't make it reappear until you reload the page. (You only check the hash once, when loading the entire page, not when the hash changes.
function showHideForm() {
if (location.hash == "" || location.hash == "#uno"){
$("#form").hide();
} else {
$("#form").show();
};
}
window.onhashchange = showHideForm;
I have found so many posts about this but I can't get this to work for the life of me. On submit of the form, I need the code to 1) submit the form and 2) redirect to one of the locations inside the case statements. I can get the form to submit without the cases and I can get the form to redirect, but I can't get it to do both. Please tell me I am on the right track but just have code in the wrong spot, I have been staring at this way too long and have hit a roadblock.
$("#submitBtn").click(function (event) {
event.preventDefault();
var validator = $(this).closest("form").kendoValidator({
messages: {
required: function (input) { return getRequiredValidationMessage(input) },
custom: function (input) { return getInvalidValidationMessage(input) },
},
rules: {
custom: function (input) {
var minlength = $(input).attr('data-minlength');
var required = $(input).attr('required');
if (typeof minlength !== typeof undefined && minlength !== false && ((typeof required !== typeof undefined && required !== false) || $(input).val().length > 0)) {
var minlength = $(input).data('minlength');
return $(input).val().length >= minlength;
} else {
return true;
}
}
}
}).data("kendoValidator");
if (validator !== undefined) {
if (validator.validate()) {
$("aspnetForm").submit();
if ($("aspnetForm").submit()){
switch(document.getElementById('interests').value){
case "stair-lifts":
window.location.href="/Catalog/Online-Catalog-Category/15522/Stair-Lifts";
break;
case "wheelchair-ramps":
window.location.href="/Catalog/Online-Catalog-Category/15521/Ramps";
break;
case "roll-in-barrier-free-showers":
window.location.href="/Catalog/Online-Catalog-Category/15529/Bathroom-Safety";
break;
case "walk-in-tubs":
window.location.href="/Catalog/Online-Catalog-Category/15529/Bathroom-Safety";
break;
case "patient-lifts-ceiling-lifts":
window.location.href="/Catalog/Online-Catalog-Category/15523/Patient-Lift";
break;
case "wheelchair-lifts":
window.location.href="/Catalog/Online-Catalog-Category/15525/Wheelchair--Scooter-Lifts";
break;
default:
window.location.href="/"; // if no selection matches then redirected to home page
break;
}// end of switch
}
} else {
$('.k-invalid:first').focus();
$('.k-invalid').blur(function () { if (this.checkValidity()) { $('.k-invalid:first').focus(); } });
}
} else {
$(this).closest("form").submit();
}
});
});
You shouldn't be using .submit() for this. Since you're using JQuery, you should use an AJAX request, formatted something like this:
$("#submitBtn").click(function (event) {
$.ajax({
url : "/your/url", // Whatever URL you're submitting to goes here
type : "post",
data : yourData, // Whatever data you're sending goes here
success : function(data) {
// Whatever you want to do on success goes here
}
});
});
You make the switch in URL part of the function the AJAX query executes on success.
The form submission and the page redirect are clashing because in a basic web page, only one of these can occur. When the form submits, it will send the form data via the desired method to the server - typically a GET or a POST.
Conversely, when that redirect switch statement runs, it will tell the browser to change the page url.
Both of these events will trigger a page change within the browser, but only one can truly happen.
What would help you the most is to submit the form data via an AJAX request and then on completion call the redirect code.
As it looks like you are already using jQuery, check out the post method here.
I have an ASP.NET web forms app that contains a confirm dialog that I have successfully made to trigger when I navigate within the page. I have the page prompting the user to give confirmation to save or cancel changes. When I navigate to another link, the page does not trigger the confirmation message.
I am trying to get the following event to trigger but it only works on new requests on the "Same" page such as pressing next, back, previous, first. When I click on a menu on the page to load a new page I do not see beforeunload firing.
How can I modify the following code to provide the same confirmation when I navigate to another link by clicking on a menu in ASP.NET?
$(window).on("beforeunload", function () {
if ((updateCancelClicked == false) && ($("#MainContent_ErrorContent").text() != "No Action Items Found.") &&
($("#FormChanged").val() == "true") || ($("#MainContent_btnUpdateItem").is(":disabled") == false) &&
($("#MainContent_btnCancelItem").is(":disabled") == false)) {
if ((!firstConfirm || $("#MainContent_btnUpdateItem").is(":enabled")) && $("#MainContent_ConfirmAlertOn").val() == "True")
{
firstConfirm = true;
confirmVal = confirm("Save changes? \"OK\" saves changes. \"Cancel\" removes changes.");
}
if (confirmVal) {
$.ajax({
type: "POST",
url: "ViewEditActionItem.aspx/UpdateFormData",
data: JSON.stringify({ actionItemID: $.trim($("#MainContent_txtActionItemID").val()), assignedDate: $.trim($("#MainContent_txtAssignedDate").val()), originalDueDate: $.trim($("#MainContent_txtOriginalDueDate").val()), ECD: $.trim($("#MainContent_txtECD").val()), ClosedDate: $.trim($("#MainContent_txtClosedDate").val()), criticality: $.trim($("#MainContent_ddlCriticality").val()), category1: $.trim($("#MainContent_ddlCategory1").val()), category2: $.trim($("#MainContent_ddlCategory2").val()), ownerUserID: $.trim($("#MainContent_ddlOwner").val()), altOwnerUserID: $.trim($("#MainContent_ddlAltOwner").val()), actionItemTitle: $.trim($("#MainContent_txtActionItemTitle").val()), progressID: $.trim($("#MainContent_ddlProgress").val()), actionItemStatement: $.trim($("#MainContent_txtActionItemStatement").val()), closureStatement: $.trim($("#MainContent_txtClosureStatement").val()), closureCriteria: $.trim($("#MainContent_txtClosureCriteria").val()), notes: $.trim($("#MainContent_txtNotes").val()) }),
contentType: "application/json",
dataType: "json",
async: false
});
}
}
else {
$("#MainContent_ConfirmAlertOn").val("True");
return;
}
});
I have a strange problem, but it doesnt seem like I can find a solution:
I want to enter the edit mode of the WebDataGrid, when the user navigates from page X to the page with the grid.
My code is something like this:
function GridRowEnterEditMode(src, validationGroup) {
var savePageValidate = undefined;
if (typeof (Page_ClientValidate) != "undefined") {
savePageValidate = Page_ClientValidate;
Page_ClientValidate = undefined;
}
var row = jQuery(src).parents("tr[type='row']").get(0)._object;
var editingCore = row.get_grid().get_behaviors().get_editingCore();
if (editingCore != null) {
var rowEditingTemplate = editingCore.get_behaviors().get_rowEditingTemplate();
if (rowEditingTemplate != null) {
rowEditingTemplate.enterEditMode(row);
}
}
if (savePageValidate != undefined) {
Page_ClientValidate = savePageValidate;
}
if (typeof (Page_ClientValidate) != "undefined" && validationGroup != null) {
Page_ClientValidate(validationGroup);
}
}
While it works when I shoot this when a button is clicked, it seems like I cant find the correct event to load this after the page is loaded client side.
I tried document.ready, document.load, pageLoad, I setted a timer for a delay etc. etc., it always shoots at this code:
var row = jQuery(src).parents("tr[type='row']").get(0)._object;
Has anyone a idea, what I can do to delay this further or if there is a infragistics way to get this?
I asked in their forum as well, but didnt get a helpfull answer so far.
Matthias