ajax jquery与json没有在IE上工作

时间:2010-11-09 04:13:34

标签: jquery ajax

下面的代码完全适用于除IE之外的所有浏览器。如果有人可以帮我解决这个问题,那真的很棒!

$(document).ready(function(){
 $('#signup-form').submit(function(){

  //check the form is not currently submitting
  if($(this).data('formstatus') !== 'submitting'){

   //setup variables
   var form = $(this),
    formData = form.serialize(),
    formUrl = form.attr('action'),
    formMethod = form.attr('method'),
    responseMsg = $('#form-response');

   //add status data to form
   form.data('formstatus','submitting');

   //show response message - waiting
   responseMsg.hide()
        .addClass('response-waiting')
        .text('Please Wait...')
        .fadeIn(200);

   //send data to server for validation
   $.ajax({
    url: formUrl,
    type: formMethod,
    data: formData,
    success:function(data){

     //setup variables
     var responseData = jQuery.parseJSON(data),
      klass = '';

     //response conditional
     switch(responseData.status){
      case 'error':
       klass = 'response-error';
      break;
      case 'success':
       klass = 'response-success';
      break;
     }

     //show reponse message
     responseMsg.fadeOut(200,function(){
      $(this).removeClass('response-waiting')
          .addClass(klass)
          .text(responseData.message)
          .fadeIn(200,function(){
           //set timeout to hide response message
           setTimeout(function(){
            responseMsg.fadeOut(200,function(){
                $(this).removeClass(klass);
             form.data('formstatus','idle');
            });
           },3000)
        });
     });
    }
   });
  }

  //prevent form from submitting
  return false;
 });
});

1 个答案:

答案 0 :(得分:1)

试试这个

var form = $(this),
var formData = form.serialize(),
var formUrl = form.attr('action'),
var formMethod = form.attr('method'),
var responseMsg = $('#form-response');

习惯使用var来声明变量。 没有var,有时它在IE中工作

Amit Battan