使用jQuery的$就功能使用JSON和PHP如何上传文件 [英] How can i upload a file using jquery's $.ajax function with json and php

查看:179
本文介绍了使用jQuery的$就功能使用JSON和PHP如何上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传使用jQuery的 $。阿贾克斯功能的文件,但没有得到任何输出。 有人请帮我解决这个问题。 我不知道这个脚本是正确的。 我的脚本是:

I am trying to upload a file using jQuery's $.ajax function but didn't get any output. Somebody please help me to solve this. I don't know if this script is correct. My script is:

$.ajax({
  url:'newsup.php',
  data: "",
  type: 'POST',
  contentType:'multipart/form-data',
  dataType: 'json',
  catche: 'false',

  success:function(data6)
  {
    $("#disp").removeClass().addClass((data6.error=== false)? 'success':'error').html(data6.msg).fadeIn('fast');
    //dele();
    if($("#disp").hasClass('success'))
    {
      alert("success");
      setTimeout("$('#disp').fadeOut('slow')",3000);            
    }
  },

  error:function(XMLHttpRequest,textStatus,errorThrown)
  {
    $("#disp").removeClass().addClass('error').html("There was an <strong>"+errorThrown+"</strong> error due to  <strong>"+textStatus+" condition").fadeIn('fast');
  }              

});

此外,我需要帮助使用jQuery的文件上传现场获取的数据。

Also I need help getting data from file uploading field using jQuery.

推荐答案

AJAX犯规支持文件上传。还有像 ajaxfileupload 基本上创建了一个隐藏的表单和动态上传文件的插件。

AJAX doesnt support file uploading. There are plugins like ajaxfileupload which basically creates a hidden form and uploads your file dynamically.

看看<一href="http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery">here和阅读奥利奇的答案

take a look here and read Oli's answer

这篇关于使用jQuery的$就功能使用JSON和PHP如何上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆