Jquery ajax post调用在主机中发送阵列时导致400(错误请求)。对于VisualStudio来说效果很好
有人知道为什么Iam在发送数组时收到错误400的ajax请求吗。对我来说,奇怪的是,在VisualStudio中,它工作得很好,但当将项目上传到主机时,开始出现这种类型的错误 Iam所做的是通过以下方式创建阵列:Jquery ajax post调用在主机中发送阵列时导致400(错误请求)。对于VisualStudio来说效果很好,jquery,ajax,3-tier,Jquery,Ajax,3 Tier,有人知道为什么Iam在发送数组时收到错误400的ajax请求吗。对我来说,奇怪的是,在VisualStudio中,它工作得很好,但当将项目上传到主机时,开始出现这种类型的错误 Iam所做的是通过以下方式创建阵列: SharedImages.push({ PathToFile: "/Images/image.png", ContentType: "png", FileName: "image"}); 使用ajax: type: "POST", url: url + "ajaxreques
SharedImages.push({ PathToFile: "/Images/image.png", ContentType: "png", FileName: "image"});
使用ajax:
type: "POST",
url: url + "ajaxrequest" ,
data: JSON.stringify({
CountryId: 1,
CityId: 1,
Place: "1",
SharedImages: SharedImages //aray of objects without this line all works fine
}),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
crossDomain: true,
cache: false,
success: function
在另一节课上学习:
[OperationContract(Name = "ajaxrequest")]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public string ajaxrequest(int CountryId, int CityId, string Place, List<SharedImages> SharedImages)
{
}
不要认为你可以JSON.stringify一个图像,你为什么要首先使用stringify呢?好吧,数据应该作为JSON对象发送,这是我的错误。尝试将二进制文件保存到服务器根文件夹时出现问题。它与ajax没有任何关系。。。
public class SharedImages{
public string PathToFile { get; set; }
public string ContentType { get; set; }
public string FileName { get; set; }}