用xhr的ajax无法运行成功的回调函数

时间:2014-08-25 08:01:42

标签: javascript ajax node.js

我正在编写一个html页面,它使用ajax和 xhr 将表单数据(包括文本和文件)上传到nodejs服务器。
 但是在nodejs服务器收到数据并发回一个字符串后,#34; 1"到前端.js代码无法运行其成功的回调函数。

function show_status(status) {
     alert(status);
     if (status == '1') {
         $('#status').text('Add game succeed!!');
     } else {
         $('#status').text('Add game failed!!');
     }
 }
 $(document).ready(function() {
     $('#addformonline').submit(function(e) {
         $('#status').text('');
         $.ajax({
             type: 'POST',
             dataType: 'text',
             xhr:function() {
                 myXhr = $.ajaxSettings.xhr();
                 return myXhr;
             },
             data: new FormData($('#addformonline')),
             success: show_status,
             error: function(){alert('error');}
          });
          return false;
       }); 
  });

0 个答案:

没有答案
相关问题