powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / submit fileupload и callback
6 сообщений из 6, страница 1 из 1
submit fileupload и callback
    #38074828
Фотография Judo
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Добрый день
Пользователь выбирает файл, далее он отсылается серверу, который его обрабатывает и возвращает некий результат json. В зависимости от результата javascript должен выполнить манипуляции с интерфейсом.
Как повесить callback фукнцию на $.submit() - ? (тут идет загрузка файла).
Как вариант пробовал использовать ajaxSubmit / ajaxForm - - скопипастив пример - но результат всегда почему вызывается error. (при этом stateCode - пустой).
Нужно именно дождаться обработки файлов $.submit() и только после этого дернуть success callback.
Кто знает как ?
...
Рейтинг: 0 / 0
submit fileupload и callback
    #38075958
Фотография Judo
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Подскажите кто использовал ajaxSubmit ? у меня почему-то всегда проваливается в функцию error
...
Рейтинг: 0 / 0
submit fileupload и callback
    #38076116
IDVsbruck
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Давай свой код.
...
Рейтинг: 0 / 0
submit fileupload и callback
    #38076215
Фотография Judo
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
IDVsbruckДавай свой код.

JudoajaxSubmit / ajaxForm - - скопипастив пример - но

Код: javascript
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.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
// prepare the form when the DOM is ready 
$(document).ready(function() { 
    var options = { 
        target:        '#output2',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
        error: MyError
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind to the form's submit event 
    $('#myForm2').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
}); 
 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText, xhr, $form)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
} 

function MyError(a,b,c,d){
  console.log('in error');
  console.log(a);
  console.log(b);
  console.log(c);
  console.log(d);
}



http://jquery.malsup.com/form/#ajaxSubmit

Сервер отвечает успехом (проверено на $.post() ) - но для ajaxSubmit всегда дергается MyError (В фаербаге у меня строка post красным - stateCode пустой).

Там на сайте есть примеры но они юзают:
Код: html
1.
<form id="myForm2" action="dummy2.php" method="post"><div>


И чтото я не пойму почему у них работает а у меня нет.
...
Рейтинг: 0 / 0
submit fileupload и callback
    #38076878
IDVsbruck
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А сервер получил запрос, обработал и вернул?
...
Рейтинг: 0 / 0
submit fileupload и callback
    #38077097
z-js
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Judo...и возвращает некий результат json...

Может заголовков не хватает?
Код: vbnet
1.
2.
3.
Accept: application/json в запросе
и
Content-Type: application/json в ответе
...
Рейтинг: 0 / 0
6 сообщений из 6, страница 1 из 1
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / submit fileupload и callback
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]