The ajaxForm function is not working well. It returns an error.

Here is my code:

Html:

<form class="t1-form" action="ajax/upload.php" method="post" accept-charset="UTF-8" id="form" enctype="multipart/form-data">
<textarea class="txtbox" placeholder="" role="textbox" title="" name="post"></textarea>
<div class="photo-selector"><button type="button" class="btn btn-default" title="attach image"><i class="fa fa-camera fa-fw"></i>&nbsp;Upload</button><div class="image-selector"><input type="hidden" name="photoId" value="" id="photoId" class="file-data" autocomplete="off"><label class="t1-label"><span class="visuallyhidden">Add photo</span> <input type="file" class="file-input _5f0v" tabindex="-1" name="photo" title="Choose nah" id="photoimg" accept="image/*"></label><div class="swf-container"></div></div></div>

</form>

Javascript:

$(document).ready(function($) {
    //=================== * UPLOAD  * ===============//
    $('input[name="photo"]').live('change', function(){          
    //$('<div id="loader_gif"></div>').insertBefore('#upload');
    $('._xdpm').attr({'disabled' : 'true'}).css({'opacity':'0.5','cursor':'default'});
    $('.txtbox').attr({'disabled' : 'true'}).css({'opacity':'0.5'});


      (function() {

      $("#form").ajaxForm({
      dataType : 'json',  
      success:  function(data)
      {
        if( data ) {

          $('._xdtxt').removeAttr('disabled').css({'opacity':'1'});
          if( data.error == 1 ) {
            alert('Error:'+data.output);
            //$('#loader_gif').remove();
          }

          //$('#wrapper_preview').show();
         // $('#container_preview').html( ''+ data.output +'' ).show();
          $('._5f0v').val('');

          if( data.error == 0 ) {
            //$('#loader_gif').css({background:'url("<?php echo URL_BASE; ?>thumb_fixed/30-30-tmp/'+ e.photo +'") center center no-repeat #FFF'}).addClass('deletePhoto').attr( 'data',e.photo ).attr( 'title','<?php echo $_SESSION['LANG']['delete_image']; ?>' );
            //$('#wrapper_preview').show();
            $('#photoId').val(data.photo);
            $('._xdpm').removeAttr('disabled').css({'opacity':'1','cursor':'pointer'});
          }

        } else {
          alert('Unknown error');
          $('._5f0v').val('');
          $('._xdpm').removeAttr('disabled').css({'opacity':'1','cursor':'pointer'});
          //$('#loader_gif').remove();

        }
      }//<----- SUCCESS

    }).submit();

    })(); //<--- FUNCTION %
  });//<--- LIVE
});

Help would be much appreciated..Thanks

What's the error?

It returns "Unknown error". Triggered by:

Javascript:

if( data ) {

/*success*/
} else {
          alert('Unknown error');

          }

That's not a javascript error... The alert is executing because your if..else condition on line 15 above is returning false.

have you tried using your browser's dev tools (f12)? i like chrome's console, but the other browsers have them as well. you can inspect the traffic being sent to/from the client/server and see if you can figure out what else is happening here..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.