Javascript Alert box not displaying on Firefox - javascript

Okay,
so I have this script which works fine with IE but won't work with Firefox. So I was wondering if anyone has had this problem and maybe got a solution.
$.ajax({
type : "POST",
url : "../php/insertUser.php",
data : dataString,
success : function(msg, status)
{
var reply = parseInt(msg);
if(reply==1)
{
alert('Email address already exists in our members database.\n'+
'Please try another address and then submit it again!');
}
else if(reply==2)
{
}
else if(reply==0)
{
$('#pForm').hide('fast');
$('#accForm').show('slow');
}
}
});
So, the alerts are working fine on IE but I can't get them to work on Firefox (3.6 or earlier). Any ideas as why this might happen?
EDIT: Thanks to TJ for referring me to the Firebug, now I see that the alerts are not the problem. The problem lies in that Firefox is not reading the "success:" clause. Any ideas?

There's nothing wrong with the alert as far as one can see (once I reformatted the code to make it readable! ;-) ). My suggestion is to get Firebug and step through the code, seeing where it's failing. For instance, the most likely reasons you're not seeing the alert are that the Ajax call is failing or you're never getting reply = 1 from parsing msg.

Related

What caused the "Unchecked runtime.lastError: The message port closed before a response was received." warning?

I have searched around but it's all about people complaining the bug. Many posts say that you should check all your extensions.
However, this is something I encountered when I am developing an extension.
Here is how it happens:
I have a listener on background.js:
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
console.log('get:', request);
if (request.hasOwnProperty('opt')) {
trackPage('opt/' + request.opt);
}
return Promise.resolve("");
});
And here is the trigger in my option page:
track('something');
function track(msg){
chrome.runtime.sendMessage({opt: msg}, function(response) {
console.log(response);
});
}
The error occurs when the track function is fired.
How can I fix the error totally?
You can't return a Promise to make the function async, you have to return true. So change this:
return Promise.resolve("");
To this:
Promise.resolve("").then(result => sendResponse(result));
return true;
I'm not sure why all the "it's Chrome extensions" responses are down-graded. I turned off all extensions; problem gone. Tried different browsers (even Microsoft); no problem. Back to Chrome and turned one extension back on; problem returned. Tried with a simple web page: <?php ; (yes, nothing) problem persists.
So, fuggedaboudit. Or, quoting Bill Murray in "Meatballs," "It just doesn't matter!"
If you see this error on other websites too then don't be bothered because it's not generated by your app, probably some Chrome Extension.
I disabled Tampermonkey Chrome extension and the error disappeared.
check extentions chrome, update or remove or deactive

Meteor method not working properly in mozilla

I am trying to make a call to a meteor method, to insert a document before redirecting the user to the relevant url (using the generated document _id).
The code currently works on chromium but not on firefox, where on firefox it appears to just get redirected right away without actually inserting anything.
I've attached my code at the bottom. Can anyone tell me what went wrong and what can I do to fix it? Why will chrome and firefox behave differently in this situation?
Any help provided is greatly appreciated!
client.js
newDoc(){
Meteor.call('addDoc',{
// some parameters
})
}
clientandserver.js (Meteor method)
'addDoc'(obj){
console.log(obj); // does not output anything on firefox
DocumentData.insert({
//some parameters
},function(err,documentID){
if (Meteor.isClient){
window.location = '/docs/' + documentID;
// redirection happens before insertion on firefox
}
});
}
Bring window.location to the client side. Like:
newDoc(){
Meteor.call('addDoc', data, function(error, result){
if(result){
window.location = '/docs/' + documentID;
}
})
}
And put only the insertion in server side, like:
'addDoc'(obj){
return DocumentData.insert({
//some parameters
});
}
I've used this structure and it works for me in both Firefox & Chrome.

Jquery Ajax Request return forbidden (403) in cakePHP project

EDIT 2
I still need help, as the error still isn't fixed.
Below I have added a link to a screenshot of what .ajaxError() does throw:
http://i.imgur.com/RkcgNtG.jpg
Another thought was the server setting. Is there any chance that suphp or the mpm_itk module are the cause for this bug?
EDIT
I have figured out something. My Ajax-Call should update some data from an input and a textarea. I tested some more and saw that the 403 only occurs when the value of my textarea or the value of my input has more than one whitespace ... So 'that-is-a-test' and 'thatisatest' work fine, but 'that is a text' returns a 403.
I also want to add that the Ajax-Call is done with a get-method.
Original
I've got a problem working on my cakePHP project.
First of all I have to say that I am new to cakePHP and that I work on a project that was not developed by me initially.
I have set up this project on my localhost (Windows 8 with xampp) and everything works fine.
In a next step I edited the Bootstrap-Configuration file, corrected the database information and uploaded all files to my server.
Now everything still works, except for the jQuery AjaxCalls. Tracing the root of this error I saw that the server returns an 403 Status Code.
Now I searched for possible reasons. First aspect I found was to set the security-level from high to medium. But as my 2.x project does not have this setting anymore, I need another solution.
Next step was to check the server settings. But the phpinfo of both, my local version and the server where the error takes place, seem to be nearly the same.
Only the PHP version of 5.3 on the server and the use of FastCGi are different.
But as cakePHP do not need more than 5.2 that cannot be the reason.
So now I have no idea what to search for. I think it has to be one setting because it works fine on my localhost, worked fine on another server but fails on the new server.
Any ideas I could check? As I am not an expert of server technologies it would be great if you answer as detailed as possible.
thanks and greets
I have now changed my jQuery Ajax-Call that looks like following
$.ajax({
url: '/metas/saveMetas',
data: {
"model": model,
"f_key": f_key,
"pagetitle": pagetitle,
"keywords": keywords,
"description": description,
"niceurl": niceurl
},
dataType: 'json',
complete: function(){
return false;
},
success: function(result) {
if(typeof result =='object') {
$('#modal-spinner-seo-update').hide('slow');
jQuery.each(result, function(field, message) {
$('#seo-'+field).next('div.error-message').html(message).fadeIn('fast');
});
} else {
$('#modal-spinner-seo-update').hide('slow', function() {
$("#seo-widget-message-success").fadeIn('slow').delay(2000).fadeOut('slow');
});
}
return false;
}
});
into a simple JavaScript xmlHttpRequest as following
xhr = new XMLHttpRequest();
xhr.onreadystatechange=function()
{
if (xhr.readyState==4 && xhr.status==200)
{
console.log(xhr.responseText);
if(typeof xhr.responseText =='object') {
$('#modal-spinner-seo-update').hide('slow');
jQuery.each(result, function(field, message) {
$('#seo-'+field).next('div.error-message').html(message).fadeIn('fast');
});
} else {
$('#modal-spinner-seo-update').hide('slow', function() {
$("#seo-widget-message-success").fadeIn('slow').delay(2000).fadeOut('slow');
});
}
return false;
}
};
xhr.open('GET','/metas/saveMetas?model='+model+'&f_key='+f_key+'&pagetitle='+pagetitle+'&keywords='+keywords+'&description='+description+'&niceurl='+niceurl, true );
xhr.send();
and now everything seems to work fine. But I still do not understand why. Can anyone explain what I did wrong?

Javascript works in Chrome, Safari and Opera but not Firefox

Site here.
Basically the box in the middle doesn't generate random string from my database in Firefox as it does in the other browsers. I can't seem to find the problem, my JS skills aren't amazing.
I haven't tested it in IE as I don't have access to it right now.
Any ideas?
Thank you!
The problem is that form is not defined where you're using it in firefox, you could write it a bit differently to be cross-browser compatible like this:
function get() {
$('#dare').fadeOut(500);
$.post ('data.php', $("form").serialize(), function(output) {
$('#dare').html(output).fadeIn(500);
});
}
The .serialize() function will take every input element in the form a serialize it, resulting in the same request all the other browsers are making...in a lot less code :)
Check the error message in firebug:
form is not defined
$.post ('data.php', {name: form.name.value, mode: mode, player: player},
The following error is generated when you view the site in Firefox:
Error: form is not defined
Source File: http://saucydares.freehostia.com/saucy.php
Line: 29
The line in question is
$.post ('data.php', {name: form.name.value, mode: mode, player: player},
I think the correct method for what you're doing here (if I interpret what you're doing here correctly) is to obtain the form's name with jQuery.

onclick event not working in firefox but works fine in IE

I got a simple form and it works fine in ie but not working in firefox
onclick="login('loginuser','../private/loginuser.php?username='+email.value+'&pass='+passw.value,'loginresult');"
Any help appreciated.
You should start by putting some alert calls in your login function to make sure that your arguments are getting quoted properly. Something like
function login (username, password, result) {
alert(username);
alert(password);
alert(result);
.... rest of function
}
That's not really a form, just an attribute snippet. Install Firebug add-on for Firefox (https://addons.mozilla.org/en-US/firefox/addon/1843/) and eliminate the guesswork by debugging the javascript. You can set a breakpoint in your login() function and see if everything is ok there or if at least if it gets called.

Categories

Resources