views:

207

answers:

2

Hi,

I am using jQuery.ajax function to make an ajax call to a page method in asp.net. I specifically set the content-type to "application/json; charset=utf-8". When I looked at the response in the firebug it says the content-type is html.

Following is the code to 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
        });
+1  A: 

You request a certain content type, but if your script does not handle this request by setting the response headers accordingly, you let IIS decide what to return. Just force the header to the right value.

greg0ire
how would I do that? The page methods are in asp.net page.
Sridhar
I don't know asp at all but in symfony php framework, you would do this : $this->getResponse()->setHttpHeader('Content-type', 'application/json');Search for something similar...
greg0ire
I will try and let you know.
Sridhar
No. That didn't work.
Sridhar
when I look at the firebug, it gives the content type as "application/json" now. but the data I am getting back is not "json". It is sending some funky characters.
Sridhar
Like in this topic : http://stackoverflow.com/questions/2989848/how-to-avoid-strange-characters-before-the-request-in-firefox ?
greg0ire
A: 

I am missing the "ScriptModule" tag in the web.config on the server. After I added that tag everything worked fine.

Thanks for your help.

Sridhar