2016-07-11 2 views
0

Когда я пытаюсь запустить следующий JQuery ajax, я получаю сообщение об ошибке, указывающее, что параметр отсутствует, и он не будет отправлять данные. Я не могу найти никаких синтаксических ошибок. Что я делаю не так?Получение ошибки при попытке отправки данных с помощью JQuery ajax

Вот Javascript с кодом Ajax JQuery:

function submitAction(actionname) {  

    if (actionname == "illustrationgenerate.htm") { 

     var thisForm = document.getElementById("illustrationTypeForm"); 
     var fd = new FormData(thisForm); 
     $.ajax({ 
      url: "illustrationgenerate.htm", 
      type: "POST", 
      data: fd, 
      datatype: "xml", 
      cache: false, 
      success: function (result, status, xhr) { 
       document.getElementById('errorMessage0').value="Success"; 
      }, 
      error: function (xhr, status, error) { 
       alert(xhr.status); 
       alert(request.responseText); 
      }       
     }); 

    } else { 
     document.forms[0].action = actionname; 
     document.forms[0].method = "POST"; 
     document.forms[0].target = ''; 
     document.forms[0].submit(); 
    } 
} 
+0

Где эта ошибка появляется и где вы называете эту функцию? Указан ли этот параметр? –

+1

Это 'dataType', не так ли? С большим Т. Или, возможно, это не имеет значения. –

+0

Какая ошибка? – epascarello

ответ

0

Почему бы не использовать JQuery родной формы кодировщик?

$.ajax({ 
      ... 
      data: $('#illustrationTypeForm').serializeArray(), 
      ... 

     }); 
0

Try This

Вот Javascript с кодом Ajax JQuery:

function submitAction(actionname) {  

    if (actionname == "illustrationgenerate.htm") { 

     var thisForm = document.getElementById("illustrationTypeForm"); 
     var fd = new FormData(thisForm); 
     $.ajax({ 
      url: "illustrationgenerate.htm", 
      type: "POST", 
      data: $('#illustrationTypeForm').serializeArray(), 
      datatype: "xml", 
      cache: false, 
      success: function (result, status, xhr) { 
       document.getElementById('errorMessage0').value="Success"; 
      }, 
      error: function (xhr, status, error) { 
       alert(xhr.status); 
       alert(request.responseText); 
      }       
     }); 

    } else { 
     document.forms[0].action = actionname; 
     document.forms[0].method = "POST"; 
     document.forms[0].target = ''; 
     document.forms[0].submit(); 
    } 
} 
0

Чтобы сделать запрос Ajax с помощью JQuery типа 'POST', вы можете сделать это с помощью следующего кода:

$.ajax({ 
    url: "test.php", 
    type: "post", 
    data: values , 
    success: function (response) { 
     // you will get response from your php page (what you echo or print)     
    }, 
    error: function(jqXHR, textStatus, errorThrown) { 
     console.log(textStatus, errorThrown); 
    } 
});