0

does anyone knows why Iam getting error 400 for ajax request when Iam sending array. The strange thing for me is that in visual studio it works fine, but when uploaded project to hosting, started to get this type of error.

What Iam doing is creating array by this way:

SharedImages.push({ PathToFile: "/Images/image.png", ContentType: "png", FileName: "image"});

Using 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

and get it in another class:

 [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)
{
 }

SharedImages class lokes like

 public class SharedImages{
public string PathToFile { get; set; }
public string ContentType { get; set; }
public string FileName { get; set; }}
  • Don't think you can JSON.stringify an image, why are you using the stringify in the first place? AFAIK the data should be sent as a JSON object – Edwin Krause Jan 25 '20 at 15:48
  • It was my mistake. The problem was occurred while trying to save binary file on server root folder. It wasn't related to ajax at all... – Dmitri Dobritski Jan 28 '20 at 17:19

0 Answers0