18
18
// Check for next free Number (max. 100)
19
19
for ( i = 0 ; i < 100 ; i ++ ) {
20
20
if ( ! ( $ ( "#field_" + i ) . length > 0 ) ) {
21
- // Feld erstellen
21
+ // create Fields
22
22
html = "<tr id=\"field_" + i + "\">" ;
23
23
html += " <td>" + ( i + 1 ) + "</td>" ;
24
24
html += " <td style=\"text-align:center\">" ;
116
116
117
117
// Clicked the Button
118
118
$ ( "#doIt" ) . click ( function ( ) {
119
- $ ( "#doIt" ) . val ( "loading..." ) ;
120
- // Generate Field Data
121
- i = 0 ;
122
- while ( ( $ ( "#field_" + i ) . length > 0 ) ) {
123
- key = $ ( "#field_key_" + i ) . val ( ) ;
124
- // nur volle Keys
125
- if ( key != '' ) {
126
- value = $ ( "#field_value_" + i ) . val ( ) ;
127
- other = $ ( "#hiddenData" ) . val ( ) ;
128
- if ( other == '' ) {
129
- other = key + "=" + value ;
130
- } else {
131
- other = other + "&" + key + "=" + value ;
132
- }
133
- $ ( "#hiddenData" ) . val ( other ) ;
134
- }
135
- i ++ ;
136
- }
137
-
138
119
$ . ajax ( {
139
120
url : $ ( "#url" ) . val ( ) ,
140
121
type : $ ( "#method" ) . val ( ) ,
141
122
data : $ ( "#hiddenData" ) . val ( ) ,
123
+ beforeSend : function ( request , settings ) {
124
+ $ ( "#doIt" ) . attr ( 'disabled' , 'disabled' ) ;
125
+ $ ( "#doIt" ) . val ( "loading..." ) ;
126
+ // Generate Field Data
127
+ i = 0 ;
128
+ other = '' ;
129
+ while ( ( $ ( "#field_" + i ) . length > 0 ) ) {
130
+ key = $ ( "#field_key_" + i ) . val ( ) ;
131
+ // only existing keys
132
+ if ( key != '' ) {
133
+ value = $ ( "#field_value_" + i ) . val ( ) ;
134
+ if ( other == '' ) {
135
+ other = key + "=" + value ;
136
+ } else {
137
+ other = other + "&" + key + "=" + value ;
138
+ }
139
+ }
140
+ i ++ ;
141
+ }
142
+ settings . data = other ;
143
+ } ,
144
+ complete : function ( request , textStatus ) {
145
+ $ ( "#doIt" ) . val ( 'Send' ) ;
146
+ $ ( "#doIt" ) . attr ( 'disabled' , '' ) ;
147
+ } ,
142
148
success : function ( data ) {
143
149
$ ( '#output' ) . html ( data ) ;
144
- $ ( "#doIt" ) . val ( 'Send' ) ;
145
- $ ( "#hiddenData" ) . val ( '' ) ;
146
- }
150
+ } ,
151
+ error : function ( request , textStatus , error ) {
152
+ $ ( '#output' ) . html ( '<span style="color:red">' + textStatus + ': ' + error + '</span>' ) ;
153
+ }
147
154
} ) ;
148
155
} ) ;
149
156
@@ -238,6 +245,5 @@ <h2>REST-API Debug Tool</h2>
238
245
</ tr >
239
246
</ tbody >
240
247
</ table >
241
- < input id ="hiddenData " type ="hidden " />
242
248
</ body >
243
- </ html >
249
+ </ html >
0 commit comments