forked from alorian/bxorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-send-order.js
50 lines (43 loc) · 1.15 KB
/
example-send-order.js
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
var $orderForm = $('[name="os-order-form"]');
/**
* Serialize form data with files
*
* @param [jQueryObject] $form form for serialize.
* @return [FormData]
*/
var serializeForm = function ($form) {
var formData = new FormData();
// Append form data.
var params = $form.serializeArray();
$.each(params, function (i, val) {
formData.append(val.name, val.value);
});
// Append files.
$.each($form.find("input[type='file']"), function (i, tag) {
$.each($(tag)[0].files, function (i, file) {
formData.append(tag.name, file);
});
});
return formData;
}
$orderForm.on('submit', function(e) {
e.preventDefault();
var query = {
c: 'opensource:order',
action: 'saveOrder',
mode: 'ajax'
};
$.ajax({
url: '/bitrix/services/main/ajax.php?' + $.param(query, true),
type: 'POST',
dataType: 'json',
async: false,
cache: false,
contentType: false,
processData: false,
data: $orderForm.serialize(),
success: function (res) {
console(res);
}
});
});