I'm having trouble with updateready not firing. Is there anything I'm missing here?
window.addEventListener('load', windowLoaded, false);
function windowLoaded(e) {
window.applicationCache.addEventListener('updateready', updateReady, false);
function updateReady(e) {
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
window.location.reload();
}
};
};
Related
I am trying to force XULRunner to ignore X-Frame-Options and bypass the security warning preventing the page from loading inside an iframe.
This is what I have come up with but it doesn't work.
function myObserverXFrame()
{
this.register();
}
myObserverXFrame.prototype =
{
observe: function(aSubject, aTopic, aData)
{
var channel = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
//console.log("observing");
try
{ // getResponseHeader will throw if the header isn't set
hasXFO = channel.getResponseHeader('X-Frame-Options');
if (hasXFO)
{
// Header found, disable it
channel.setResponseHeader('X-Frame-Options', '', false);
}
}
catch (e) {}
}
},
register: function()
{
var observerService = Components.classes["#mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "http-on-examine-response", false);
observerService.addObserver(this, "http-on-examine-cached-response", false);
},
unregister: function()
{
}
}
var observer = new CommandLineObserver();
//addEventListener("unload", observer.unregister, false);
Thanks.
I managed to make this code to submit a form, it works fine, but I can not implement a validator does not need it, but it shows no message just does not send the form is empty.
I searched but could not quite do it. Can anyone help me?
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#newsletter').submit(function(){
var dados = jQuery( this ).serialize();
jQuery.ajax({
type: "POST",
url: "newsletter_cadastrar.asp?f=1",
data: dados,
success: function( data )
{
$('#resultado-form-newsletter').html(data);
}
});
return false;
});
});
</script>
<input id="nomenewslbase" name="nomenewslbase" type="text">
<input id="emailnewslbase" name="emailnewslbase" type="email">
Thank you for your attention.
If you are looking for applying jquery validation rules then you can do it like:
<script type="text/javascript">
function ValidationRules() {
}
ValidationRules.prototype.initializeSaveValidators = function() {
jQuery.validator.addMethod("csProjectName",
function(value, element) {
if ($.trim($('#txtProjectName').val()) == "") {
if ($.trim($(element).val()) != '')
return true;
else
return false;
} else
return true;
}, "Project Name is required");
jQuery.validator.addMethod("csDescription",
function (value, element) {
if ($.trim($('#txtDescription').val()) == "") {
if ($.trim($(element).val()) != '')
return true;
else
return false;
}
else
return true;
}, "Description is required");
};
ValidationRules.prototype.enableSaveValidators = function () {
jQuery.validator.classRuleSettings.csProjectName = { csProjectName: true };
jQuery.validator.classRuleSettings.csDescription = { csDescription: true };
};
ValidationRules.prototype.disableSaveValidators = function () {
jQuery.validator.classRuleSettings.csProjectName = { csProjectName: false };
jQuery.validator.classRuleSettings.csDescription = { csDescription: false };
};
jQuery(document).ready(function () {
var validationRules = new ValidationRules();
validationRules.initializeSaveValidators();
validationRules.enableSaveValidators();
$("#btnsubmit").click(function () {
applyjQueryValidation();
return false;
});
});
function applyjQueryValidation() {
var isValid = $('#newsletter').valid();
//here you can manually check for some extra validations
if (isValid==true) {
alert("valid");
//here is you ajax call
}else{
alert("invalid");
}
}
</script>
Also, you need to include jquery.validate.js
Here is the JSfiddle working example.
I am trying to handle the server error when creating/updating/deleting item from kendo grid. But when a error is thrown, the kendo grid closes no matter what.
function kendo_error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
showErrorMessages(key, message);
});
//this does not work
var grid = this;
gird.one("dataBinding", function (e) {
e.preventDefault();
});
}
}
Does anybody have any other solution? e.preventDefault() doesn't work either.
This worked for me. Just in case anybody needs this.
function kendo_error_handler(gridName) {
return function (e) {
if (e.errors) {
var grid = $('#'+gridName).data("kendoGrid");
grid.one("dataBinding", function (ev) {
ev.preventDefault();
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
showErrorMessages(key, message);
});
});
}
else {
$("#errorContainer").text("");
}
}
}
is it cause it says " gird.one(" instead of "grid.one("
I'm developing a web application with MVC 3 and want to return a message to the user after he has deleted an item successfully.
MyWallController method looks like this:
[HttpPost]
public ActionResult DeleteAlbum(Guid albumId)
{
try
{
this.albumService.DeleteAlbum(albumId);
return Json(new { success = true, msg = "Album successfully deleted" }, JsonRequestBehavior.AllowGet);
}
catch (FPSException e)
{
return Json(new { success = false, msg = e.Message });
}
catch (Exception)
{
throw new HttpException(500, "Error while deleting album");
}
}
The link:
<a class="open-DeleteAlbumDialog" href="http://localhost:2941/MyWall/DeleteAlbum?albumId=0f49b1ad-8ec1-4fca-b8e2-28bdbf47824e">Delete</a>
The JavaScript:
$(function () {
$(document).on('click', '.open-DeleteAlbumDialog', function () {
var answer = confirm('Are you sure you want to delete this album?')
if (answer) {
$.post(this.href, function (data) {
if (data.success) {
// do something
} else {
// do something else
}
});
}
else return false;
});
However the function defined inside post is never called and what I get is a "the resource cannot be found". But the item has been deleted successfully.
All kinds of help is appreciated.
Your link is still working. You need to preventDefault:
$(function () {
$(document).on('click', '.open-DeleteAlbumDialog', function (e) {
e.preventDefault();
var answer = confirm('Are you sure you want to delete this album?')
if (answer) {
$.post(this.href, function (data) {
if (data.success) {
// do something
} else {
// do something else
}
});
}
});
Just curious if there's an easy way to add functions to the $(window).load() event before it has fired. For example, if you call $(window).load() twice in the beginning of the page, only the function of the second call will execute onload.
Is there some sort of tool built into jQuery for adding to the onload event instead of replacing it? If so, how about for the $(document).ready() call?
They actually do stack in the order specified. Here's an example : http://jsfiddle.net/73D9Z/
I've used window.ready()
$(window).ready(function(){
alert('window ready 1');
});
$(window).ready(function(){
alert('window ready 2');
});
$(document).ready(function(){
alert('document ready 1');
});
$(document).ready(function(){
alert('document ready 2');
});
function windowLoad(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
function documentReady(func) {
var oldonload = document.ready;
if (typeof document.ready != 'function') {
document.ready = func;
} else {
document.ready = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
$(window).load() gets executed after a page is rendered.
$(document).ready(handler) executes the function passed as parameter, after the DOM is ready and before the page is rendered.