需要FormData的内容类型 [英] Need content type for FormData

查看:78
本文介绍了需要FormData的内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将formData或Json发送到服务器.所以我需要formData的contentType.请不要将false作为contentType值.

I am sending formData or Json to server. So i need contentType for formData. Please don't give false as contentType value.

formdata = new FormData(form[0]);
$.ajax({
    url: url,
    data: formdata? formdata :$(#User).serialize(),                 
    type: 'post',
    cache: false,
    contentType: "json",
    processData: false,
    beforeSend: function () {
        $(options.createOrUpdateRelationship).attr('disabled', 'disabled');
        var target = $(options.setupSubContainer);
        $("body").append(options.fadeoutDiv);
        options.spinner.spin(target[0]);
    },
    success: function (data) {

    }
});

推荐答案

需要提供dataType,因为以哪种格式将数据发送到服务器,例如json,array并且您可以提供formid.serialize()以查询字符串格式序列化格式数据,并将其发送到服务器,您可以通过$ _POST在php中接收数据

Need to give the dataType because in which format sending data to server for example json,array and you can give the formid.serialize() to to serialize the formadatas in a Query string format and send to server you can receive the data by $_POST in php

var form = $("#formId").serialize();
$.ajax({
type: 'POST'
url: url,
data: form,
dataType: 'json',
success: function (data) {
   //add your code
}
});

contentType已删除-我们不发送JSON.

contentType removed - we are not sending JSON.

这篇关于需要FormData的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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