[WebMethod]
public static string GetAllUnits()
{
return objSQL.GetAllUnits().GetXml();
}
I tested the code, it worked fine as long as I launch the page from Vistual Studio (either debug or release mode). The page jQuery code will call my aspx page web method to get a list of units and dynamically build a <table> at the client side. It works
perfectly and I am very pleased about it.
However, when I decided to publish and deploy the web application to my local IIS (windows 7), I don't exactly my IIS version, it is properly 7 or 7.5. But the thing is the page gets loaded but I don't have the <table> built as if the jQuery code nevers
gets any json data back from my page Web Method. And there is no error indicating where the problem is. The page gets loaded with blank content.
Anybody knows how to fix this problem? (I am using ASP.NET both tested on .net framework 3.5 and 4.0, using jQuery 1.7).
Use the browser tools in Chrome or IE to see if the request is being made and what the response is. Hit F12 and choose the Network tab then hit Ctrl + F5 to refresh the page.
Look at the response tab to see if a more detailed error message is provided.
By the way, does the code in your GetAllUnits method rely on hardcoded file paths or connection stirngs that may not be the same on the web server? You should check those as well.
You are specifying the content and the datatype as json and you are returning xml type data. Put an error function in the ajax call and debug the detail and check what exect server error is there-
I uploaded to my Dropbox and generated this public link.
The idea was from another online tutorial project and I tried to create a similiar project for my work here. But this sample project I created does not work once I deployed to my local IIS. The idea to use jQuery ajax to call [WebMethod] from my aspx page
is very helpful, but I am confused now where did it go wrong.
X-AspNet-Version:2.0.50727Server:ASP.NET Development Server/10.0.0.0Date:Mon, 26 Nov 2012 18:21:10 GMTContent-Type:application/json; charset=utf-8Content-Length:10Connection:CloseCache-Control:private, max-age=0
chj915
0 Points
8 Posts
use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 04:02 AM|LINK
I have a sample project built to test if I can use jQuery to call methods and functions directly within my aspx page.
I made it work, I have:
$.ajax({ type:'POST', url:'Default.aspx/GetAllUnits', data:'{}', contentType:'application/json; charset=utf-8', dataType:'json', ......................... });In my Default.aspx page, I have a method:
[WebMethod] public static string GetAllUnits() { return objSQL.GetAllUnits().GetXml(); }I tested the code, it worked fine as long as I launch the page from Vistual Studio (either debug or release mode). The page jQuery code will call my aspx page web method to get a list of units and dynamically build a <table> at the client side. It works perfectly and I am very pleased about it.
However, when I decided to publish and deploy the web application to my local IIS (windows 7), I don't exactly my IIS version, it is properly 7 or 7.5. But the thing is the page gets loaded but I don't have the <table> built as if the jQuery code nevers gets any json data back from my page Web Method. And there is no error indicating where the problem is. The page gets loaded with blank content.
Anybody knows how to fix this problem? (I am using ASP.NET both tested on .net framework 3.5 and 4.0, using jQuery 1.7).
Mikesdotnett...
All-Star
154941 Points
19870 Posts
Moderator
MVP
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 05:04 AM|LINK
Use the browser tools in Chrome or IE to see if the request is being made and what the response is. Hit F12 and choose the Network tab then hit Ctrl + F5 to refresh the page.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
chj915
0 Points
8 Posts
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 05:15 AM|LINK
i got this "HTTP/1.1 500 Internal Server Error".
Requst Method: POST
X-Requested-With: XMLHttpRequest
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 05:20 AM|LINK
You should always resolve the paths using ASP.Net to make sure it works correctly everywhere
Change the line as
url:'<%=ResolveUrl("Default.aspx")%>' + '/GetAllUnits',Contact me
chj915
0 Points
8 Posts
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 05:24 AM|LINK
believe me, it is not that problem. I have tried this ResolveUrl, not this causing my problem here.
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 05:42 AM|LINK
There is nothing special in jQuery AJAX which you need to configure. Give me the exact error message
Contact me
Mikesdotnett...
All-Star
154941 Points
19870 Posts
Moderator
MVP
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 06:30 AM|LINK
Look at the response tab to see if a more detailed error message is provided.
By the way, does the code in your GetAllUnits method rely on hardcoded file paths or connection stirngs that may not be the same on the web server? You should check those as well.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
asteranup
All-Star
30184 Points
4906 Posts
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 07:20 AM|LINK
Hi,
You are specifying the content and the datatype as json and you are returning xml type data. Put an error function in the ajax call and debug the detail and check what exect server error is there-
http://delicious.com/anupdg/error+pagemethod
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
chj915
0 Points
8 Posts
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 05:24 PM|LINK
Here is the screenshots I captured.
https://dl.dropbox.com/u/12019970/jQuery%20Ajax%20call%20method%20from%20page%20%20web%20method%20not%20working%20in%20IIS.docx
I uploaded to my Dropbox and generated this public link.
The idea was from another online tutorial project and I tried to create a similiar project for my work here. But this sample project I created does not work once I deployed to my local IIS. The idea to use jQuery ajax to call [WebMethod] from my aspx page is very helpful, but I am confused now where did it go wrong.
chj915
0 Points
8 Posts
Re: use $.ajax to get json data from my aspx page [WebMethod], it works in VS dev, but not in IIS
Nov 26, 2012 05:30 PM|LINK
Below is the web console info from my working version in Firefox.
Request URL:
http://localhost:62256/Default.aspx/UpdateRandomUnits
Request Method:
POST
Status Code:
HTTP/1.1 200 OK
X-Requested-With:XMLHttpRequestUser-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0Referer:http://localhost:62256/Default.aspxPragma:no-cacheHost:localhost:62256Content-Type:application/json; charset=utf-8Content-Length:2Connection:keep-aliveCache-Control:no-cacheAccept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateAccept:application/json, text/javascript, */*; q=0.01
ASP.NET_SessionId:obptnt55d4ywdc3rh4b2cx55
X-AspNet-Version:2.0.50727Server:ASP.NET Development Server/10.0.0.0Date:Mon, 26 Nov 2012 18:21:10 GMTContent-Type:application/json; charset=utf-8Content-Length:10Connection:CloseCache-Control:private, max-age=0