Onclick function not working in firefox [closed]
function get() {
$.post(
'postchatfame.php',
{
comment: postchatfamemsg.comment.value,
userid: postchatfamemsg.userid.value
},
function(output) {
$('#walls').html(output).show();
}
开发者_C百科 );
document.forms["postchatfamemsg"].reset();
}
This is my code I used as Ajax, to store information into DATABASE. and returned some information in tabular form to the same page without refreshing page.
I called this function onclick
of button by writing this code.
<input name="a" type="button" value="Share" onClick="get();"/>
Because Fx uses standards
comment: postchatfamemsg.comment.value, will not work on its own. It will work in IE for example because IE overloads the scope with all possible things, which is also why document.getElementById('formname') will work in IE and not in Fx
Use comment: document.forms["postchatfamemsg"].comment.value,
Complete code
function sedData() { // get is a poor function name, especially when you post
var form = document.forms["postchatfamemsg"];
$.post(
'postchatfame.php',
{
comment: form.comment.value,
userid: form.userid.value
},
function(output) {
$('#walls').html(output).show();
}
);
form.reset();
}
I suggest a different name for the function - some names already have a meaning in HTML and the DOM, so using such a name may conflict with them (calling a function submit
has similar problems).
Why not give it a more descriptive name - getChatFame
, for example?
Ask yourself:
- Did you define your function physically in code before trying to use it?
- Is
jQuery
or whatever library you are using loaded before you try to use$.ajax
? - Do you have errors in the JavaScript console?
- Can you verify that any part of the process worked in the troublesome browser?
精彩评论