1

I have the next code:

$.ajax({
     type: "GET",
     url: url,
     data: {language: language},
     contentType: "application/json",
     success: function (result) {
        console.log(result);
        result.forEach(function(item) {
           var option = $("");
           option.text(item);
           option.val(item);
           node.append(option);
        });
        if (self.value.country) {
            $("#countrySelect").val(self.value.country);
        }
    }
});

why at first case (when I refresh page or visit it at first time) it returns json and at the next case (postback) it returns string Then I add

dataType: "json"
And now it returns only json. Why without adding it not worked correctly? 1) with dataType enter image description here

2) without dataType (first load) enter image description here 3) without dataType (postback)enter image description here

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79

1 Answers1

1

Because without specifying dataType, it takes a guess at the type. By specifying it to JSON, it will expect a JSON data response. You also can't specify multiple data types - if you need different data types returned, you have to leave it set to the default value.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
  • but why at first case (when I refresh page or visit it at first time it returns json) and at the next case (postback) it returns string – Enver Krynitski May 02 '19 at 08:18