Project

General

Profile

1 4966 daigle
 /*
2
  *   '$RCSfile$'
3 4971 daigle
  *     Purpose: Basic Ajax utilities
4 4966 daigle
  *   Copyright: 2009 Regents of the University of California and the
5
  *               National Center for Ecological Analysis and Synthesis
6 4971 daigle
  *     Authors: Michael Daigle
7 4966 daigle
  *
8
  *    '$Author: daigle $'
9
  *      '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
10
  *  '$Revision: 4080 $'
11
  *
12
  * This program is free software; you can redistribute it and/or modify
13
  * it under the terms of the GNU General Public License as published by
14
  * the Free Software Foundation; either version 2 of the License, or
15
  * (at your option) any later version.
16
  *
17
  * This program is distributed in the hope that it will be useful,
18
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
  * GNU General Public License for more details.
21
  *
22
  * You should have received a copy of the GNU General Public License
23
  * along with this program; if not, write to the Free Software
24
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
  */
26
27 4971 daigle
/* submits a form via ajax and inserts the results into the given div
28
 *  Params:
29
 *    url - url to hit
30
 *    formId - id of the form to submit
31
 *    divId - the name of the div where the results should be put
32
 */
33 4966 daigle
function submitFormIntoDiv(url, formId, divId) {
34
	//alert('Sending form: ' + formId + " to url: " + url);
35
	var formObj = document.getElementById(formId);
36 5075 daigle
	//alert('Form object: ' + formObj);
37 4966 daigle
38
	var myRequest = new Ajax.Updater(divId, url,
39
		{	method: 'post',
40 5183 daigle
			parameters: Form.serialize(formObj)
41 4966 daigle
		});
42 5075 daigle
	//alert("after update");
43 4966 daigle
}
44
45 6667 tao
/* submits parameters serialized from a form via ajax and inserts the results into the given div
46
 *  Params:
47
 *    url - url to hit
48
 *    formId - id of the form to submit
49
 *    divId - the name of the div where the results should be put
50
 */
51
function submitFormParasIntoDiv(url, formParas, divId) {
52
	//alert('Form object: ' + formObj);
53
54
	var myRequest = new Ajax.Updater(divId, url,
55
		{	method: 'post',
56
			parameters: formParas
57
		});
58
	//alert("after update");
59
}
60
61 5075 daigle
/* submits a form via ajax and inserts the results into the given div
62
 *  Params:
63
 *    url - url to hit
64
 *    formId - id of the form to submit
65
 *    divId - the name of the div where the results should be put
66
 */
67
function submitFormObjIntoDiv(url, formObj, divId) {
68
	//alert('Form object: ' + formObj);
69
70
	var myRequest = new Ajax.Updater(divId, url,
71
		{	method: 'post',
72 5183 daigle
			parameters: Form.serialize(formObj)
73 5075 daigle
		});
74
	//alert("after update");
75
}
76
77 6646 tao
/* submits a form via ajax and inserts the results into the given div while it will reload the page.
78
 *  Params:
79
 *    url - url to hit
80
 *    formId - id of the form to submit
81
 *    divId - the name of the div where the results should be put
82
 */
83 6667 tao
function submitFormParasIntoDivAndReload(url, formParas, divId) {
84 6646 tao
	var myRequest = new Ajax.Updater(divId, url,
85
			{	method: 'post',
86 6667 tao
				parameters: formParas,
87 6646 tao
				onSuccess: function(reponse) {
88
					window.location.reload();
89
				}
90
			});
91
}
92
93 4971 daigle
/* submits a url via ajax and inserts the results into the given div
94
 *  Params:
95
 *    url - url to hit
96
 *    divId - the name of the div where the results should be put
97
 */
98 4966 daigle
function submitUrlIntoDiv(url, divId) {
99
	//alert('Sending url: ' + url);
100
101
	var myRequest = new Ajax.Updater(divId, url,
102
		{	method: 'get'
103
		});
104
}