These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | //################################################################################## |
||
2 | //## FORM SUBMIT WITH AJAX ## |
||
3 | //## @Author: Simone Rodriguez aka Pukos <http://www.SimoneRodriguez.com> ## |
||
4 | //## @Version: 1.2 ## |
||
5 | //## @Released: 28/08/2007 ## |
||
6 | //## @License: GNU/GPL v. 2 <http://www.gnu.org/copyleft/gpl.html> ## |
||
7 | //################################################################################## |
||
8 | |||
9 | |||
10 | function xmlhttpPost(strURL,formname,responsediv,responsemsg,scroll=false) { |
||
11 | var xmlHttpReq = false; |
||
12 | var self = this; |
||
13 | // Xhr per Mozilla/Safari/Ie7 |
||
14 | if (window.XMLHttpRequest) { |
||
15 | self.xmlHttpReq = new XMLHttpRequest(); |
||
0 ignored issues
–
show
|
|||
16 | } |
||
17 | // per tutte le altre versioni di IE |
||
18 | else if (window.ActiveXObject) { |
||
19 | self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); |
||
0 ignored issues
–
show
The variable
ActiveXObject seems to be never declared. If this is a global, consider adding a /** global: ActiveXObject */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
20 | } |
||
21 | self.xmlHttpReq.open('POST', strURL, true); |
||
22 | self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
||
23 | self.xmlHttpReq.onreadystatechange = function() { |
||
24 | if (self.xmlHttpReq.readyState == 4) { |
||
25 | // Quando pronta, visualizzo la risposta del form |
||
26 | updatepage(self.xmlHttpReq.responseText,responsediv); |
||
27 | if (scroll) { |
||
28 | document.getElementById(responsediv).scrollIntoView(true); |
||
29 | } |
||
30 | } |
||
31 | else{ |
||
32 | // In attesa della risposta del form visualizzo il msg di attesa |
||
33 | updatepage(responsemsg,responsediv); |
||
34 | |||
35 | } |
||
36 | } |
||
37 | self.xmlHttpReq.send(getquerystring(formname)); |
||
38 | } |
||
39 | |||
40 | function getquerystring(formname) { |
||
41 | var form = document.forms[formname]; |
||
42 | var qstr = ""; |
||
43 | |||
44 | function GetElemValue(name, value) { |
||
45 | qstr += (qstr.length > 0 ? "&" : "") |
||
46 | + escape(name).replace(/\+/g, "%2B") + "=" |
||
47 | + escape(value ? value : "").replace(/\+/g, "%2B"); |
||
48 | //+ escape(value ? value : "").replace(/\n/g, "%0D"); |
||
49 | } |
||
50 | |||
51 | var elemArray = form.elements; |
||
52 | for (var i = 0; i < elemArray.length; i++) { |
||
53 | var element = elemArray[i]; |
||
54 | var elemType = element.type.toUpperCase(); |
||
55 | var elemName = element.name; |
||
56 | if (elemName) { |
||
57 | if (elemType == "TEXT" |
||
58 | || elemType == "TEXTAREA" |
||
59 | || elemType == "PASSWORD" |
||
60 | || elemType == "BUTTON" |
||
61 | || elemType == "RESET" |
||
62 | || elemType == "SUBMIT" |
||
63 | || elemType == "FILE" |
||
64 | || elemType == "IMAGE" |
||
65 | || elemType == "HIDDEN" |
||
66 | || elemType == "NUMBER" |
||
67 | || elemType == "DATE" |
||
68 | || elemType == "EMAIL") |
||
69 | GetElemValue(elemName, element.value); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
70 | else if (elemType == "CHECKBOX" && element.checked) |
||
71 | GetElemValue(elemName, |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
72 | element.value ? element.value : "On"); |
||
73 | else if (elemType == "RADIO" && element.checked) |
||
74 | GetElemValue(elemName, element.value); |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
75 | else if (elemType.indexOf("SELECT") != -1) |
||
76 | for (var j = 0; j < element.options.length; j++) { |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
77 | var option = element.options[j]; |
||
78 | if (option.selected) |
||
79 | GetElemValue(elemName, |
||
0 ignored issues
–
show
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later. Consider: if (a > 0)
b = 42;
If you or someone else later decides to put another statement in, only the first statement will be executed. if (a > 0)
console.log("a > 0");
b = 42;
In this case the statement if (a > 0) {
console.log("a > 0");
b = 42;
}
ensures that the proper code will be executed conditionally no matter how many statements are added or removed. ![]() |
|||
80 | option.value ? option.value : option.text); |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | return qstr; |
||
85 | } |
||
86 | function updatepage(str,responsediv){ |
||
87 | document.getElementById(responsediv).innerHTML = str; |
||
88 | } |
||
89 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.