Jquery.ajax returns html content type in iis while it returns json content type on localhost

I use a function jQuery.ajaxto make an ajax call to the page method in asp.net. I specifically installed content-typein application/json; charset=utf-8. When I looked at the answer in firebug, he said that the content type is html.

Below is the code for my ajax call:

 $.ajax({
            async: asyncVal,
            type: "POST",
            url: url + '/' + webMethod, 
            data: dataPackage,
            contentType: "application/json; charset=UTF-8",
            dataType: "json",            
            error: errorFunction,
            success: successFunction
        });
+3
source share
3 answers

You are requesting a specific type of content, but if your script does not process this request by setting response headers accordingly, you will allow IIS to decide what needs to be returned. Just set the title to the correct value.

+1
source

ScriptModule web.config . , , .

.

+1

Add this code to your web.config file.

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.webServer>
        <handlers>
            <add name="ScriptHandlerFactory"
                 verb="*" path="*.asmx"
                 type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                 resourceType="Unspecified" />
        </handlers>
    </system.webServer>
</configuration>
+1
source

Source: https://habr.com/ru/post/1748876/


All Articles