0

I have asp.net mvc 5 project, which works fine in visual studio. But when I publish it to iis 7.5 some of the ajax responses stopped not working and the console isn't writing anything.

    var data = {};
    data.Id = "12";
    data.MemberId = $('').val();
    data.Price = $('').val();

    console.log(JSON.stringify(data));  // viewing correct json data 

    $.ajax(url, {
        type: 'post',
        cache: false,
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(data),
        success: function (data) {
            jsonObj = JSON.parse(data);
            processing(jsonObj);
        },
        error: function (xhr, errorText) {
            // don't call this function
            console.log('Error ' + xhr.responseText);
        },
    })

but if send empty data (only var data = {}, without Id, MemberId), works fine.

UPD

[HttpPost]
public JsonResult MyAction (MyJsonObject jsonObject)
{ }  

public class MyJsonObject 
{
    public int Id { get; set; }
    public int MemberId { get; set; }
    public double Price { get; set; }  
}
PChristianFrost
  • 120
  • 2
  • 13
Ildar
  • 93
  • 2
  • 11

1 Answers1

1

Reason of the problem may be CORS. You need to give permission.

<httpProtocol>
  <customHeaders>
       <add name="Access-Control-Allow-Origin" value="*" />
  </customHeaders>
</httpProtocol>

or try to add

crossDomain: true

to your ajax settings

This article may be more helpful.

Community
  • 1
  • 1