forked from luckymarmot/Paw-JavaScriptjQueryCodeGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.mustache
More file actions
50 lines (49 loc) · 1.31 KB
/
javascript.mustache
File metadata and controls
50 lines (49 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// {{{request.name}}} ({{{request.method}}} {{{url.base}}})
$.ajax({
url: "{{{url.base}}}",
type: "{{{request.method}}}",
{{#url.has_params}}
data:{
{{#url.params}}
"{{{name}}}":"{{{value}}}",
{{/url.params}}
},
{{/url.has_params}}
{{#headers.has_headers}}
headers:{
{{#headers.header_list}}
"{{{header_name}}}":"{{{header_value}}}",
{{/headers.header_list}}
},
{{/headers.has_headers}}
{{#body.has_raw_body}}
processData:false,
data:"{{{body.raw_body}}}",
{{/body.has_raw_body}}
{{#body.has_long_body}}
processData:false,
data:"", // set your body string
{{/body.has_long_body}}
{{#body.has_url_encoded_body}}
contentType:"application/x-www-form-urlencoded",
data:{
{{#body.url_encoded_body}}
"{{{name}}}":"{{{value}}}",
{{/body.url_encoded_body}}
},
{{/body.has_url_encoded_body}}
{{#body.has_json_body}}
contentType:"application/json",
data:JSON.stringify({{{body.json_body_object}}})
{{/body.has_json_body}}
})
.done(function(data, textStatus, jqXHR) {
console.log("HTTP Request Succeeded: " + jqXHR.status);
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log("HTTP Request Failed");
})
.always(function() {
/* ... */
});