Ehi
Ehi

Reputation: 43

JSON is undefined - and jquery stops working

 I have this ajax post which worked when I used test values

However on changing it to real meaningful values (e.g I used my family names as return values)

After changing it to (Output, SQuantity, Output and total) it stopped working. Here is my code below

please advise

function ehi(e) {

var fd = new FormData($("#Shops")[0]);
$.ajax({

    type: "POST",
    url: "/Shopping_Basket/Shop_AddToBasket", //
    contentType: false,
    processData: false,
    data: fd,
    success: function (message) {


        $('#Ok').show();
        $('#list').show().html(message.MyStatus + ' ' + message.SQuantity + ' ' +  message.Output + '   ' + message.Total);
    },
    error: function (message) {
    }
});





/// and on the server side 
   public async Task<ActionResult> Shop_AddToBasket(Duo_Basket_and_Products model)
    {
       var message = new { MyStatus = "0", SQuantity = "1000", Output ="Success", Total = "test"};
                return Json(message);

Upvotes: 0

Views: 35

Answers (1)

Ehi
Ehi

Reputation: 43

i found out the problem,

Microsoft .asp.net core controllers return JSON arrays with lower case letters. So i changed it to all small caps and its working now

thanks

Upvotes: 1

Related Questions