Problem - I have deployed mvc application in localhost webserver and add all supporting file in webserver , and my application run successfully but Jquery/Json/getjson() method is not working. i don`t know ,what is the problem?
(I assume you are calling this from some AJAX script) 2 things you could check to start with:-
1 - are you sure your URLs are getting resolved correctly in your deployed version. I found that using a jquery call like
I had to set the url parameter like this (for example):-
to access the JSONData controller / GetData action. Try looking at your page-source and making sure that (however you do it, via regular javascript, jquery, etc) the AJAX call's URL is correct and absolute to the root of the app - one possible pitfall, as far as I have seen, with using AJAX with MVC is that you have to be careful of your URL paths, especially if you have common views (especially if you use partial views) as they may be called from different "depths" or URL. e.g. I have a few partial views that are search popups and they may be called from <app-root>/<controller> or <app-root>/<controller>/<action> depths so they all have to make their AJAX calls with a base url of <app-root>.
If you are absolutely sure that it correct, try accessing your data directly using WGET (see the bottom for it's location, if you don't have it already). You can the use it to check the output of your code that is producing your JSON data to see if that is the problem, or if it's the code that is handling it (or an incorrect URL, as mentioned above) that is at fault. One of the problems with using AJAX is that it isn't always that easy to find/debug any client-side scripting issues.
If you need to send POST data, you can use something like
to test on your dev server (this will save the raw data returned to a file) - edit the URL and port to fit your dev server's port and the URL of your JSON data provider - this will send the data "123" with a form input name of "abc" (if you need to POST). Obviously if you are just using an http GET you can leave out the --post-data param and append any parameters to the URL with a ? - e.g. http://localhost:12345/scripts/myjsondata?searchValue=123 . You can then do this against the deployed version to see what you get out from that, e.g.
I the above post doesn't make sense and you are using AJAX, can you post back the source code of your calling page, along with the rendered html from your development page and also your deployed page, please?
Please remember to mark replies as answers if you find them useful =8)
Q: How do I reference scripts?
A: <script src="<%= Url.Content("~/Public/Scripts/RunActiveContent.js") %>" type="text/javascript"></script> CDN is the best approach:
<script
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.js"
type="text/javascript"></script>
This point is an extension of what I was saying and is another easy problem to come across in general. As a quick test I also deploy the app to a subdirectory of the document root inetpub/wwwroot on IIS on my machine (so it will be published to http://localhost/apps/<appname>
for example) so I can see if the links should work ok in a deployed environment.
Please remember to mark replies as answers if you find them useful =8)
Marked as answer by ricka6 on Oct 30, 2009 01:51 AM
sumit565
Member
1 Points
28 Posts
jquery/json doesnot work after deployment of asp.net mvc application
Oct 28, 2009 05:14 AM|LINK
Environment used - Asp.net mvc 1.0 with c#
Problem - I have deployed mvc application in localhost webserver and add all supporting file in webserver , and my application run successfully but Jquery/Json/getjson() method is not working. i don`t know ,what is the problem?
anyone who know the solution,
Please reply to me.
thanks
sumit
Mad-Halfling
Participant
1438 Points
729 Posts
Re: jquery/json doesnot work after deployment of asp.net mvc application
Oct 28, 2009 10:27 AM|LINK
(I assume you are calling this from some AJAX script) 2 things you could check to start with:-
1 - are you sure your URLs are getting resolved correctly in your deployed version. I found that using a jquery call like
and see if the data is still coming out correctly.
I have had WGET for ages, I believe I got it from
http://www.gnu.org/software/wget/
or
http://gnuwin32.sourceforge.net/packages/wget.htm
- I am sure they are both safe and correct, but make sure you virus check any software you download from there.
Mad-Halfling
Participant
1438 Points
729 Posts
Re: jquery/json doesnot work after deployment of asp.net mvc application
Oct 28, 2009 10:42 AM|LINK
I the above post doesn't make sense and you are using AJAX, can you post back the source code of your calling page, along with the rendered html from your development page and also your deployed page, please?
sumit565
Member
1 Points
28 Posts
Re: jquery/json doesnot work after deployment of asp.net mvc application
Oct 28, 2009 12:56 PM|LINK
I am using following code :
Controller code:
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public JsonResult GetColumn(String item)
{
String s;
if (item == "select")
{
s = "";
return this.Json(s);
}
else
{
List<Folderid> list1 = Folderid.GetFolderid().ToList();
return this.Json(list1);
}
}
}
Class that populate item list :
public class Folderid
{
public string ICPartID { get; set; }
public string CountryName { get; set; }
public static List<Folderid> GetFolderid()
{
return new List<Folderid>
{
new Folderid {
ICPartID = "DeletedItems",
CountryName = "United-States"
},
new Folderid{
ICPartID = "Inbox",
CountryName = "United-States"
} ,
new Folderid{
ICPartID = "Outbox",
CountryName = "United-States"
} ,
new Folderid{
ICPartID = "SentItems",
CountryName = "United-States"
} ,
new Folderid{
ICPartID = "LostandFound",
CountryName = "United-States"
}
};
}
}
Global.asax code:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"GetColumn",
"GetColumn/{item}",
new { controller = "Home", action = "GetColumn", item = "" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
View (index.aspx) code:
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
$(document).ready(function() {
$('#dropdownlist1name').change(function() {
$.getJSON("Getcolumn/" + $("dropdownlist1name > option:selected").attr("value"),
null,
function(data) { addCustomers(data); });
});
});
function addCustomers(data) {
// remove any existing item
$('#dropdownlist2name >option').remove();
var list = $("dropdownlist2name")[0];
// Loop over the returned collection
for (var i = 0; i < data.length; i++) {
var cust = data[i];
var option = new Option(cust.ICPartID, cust.ICPartID);
list.add(option);
};
};
</script>
<select id="dropdownlist1name" name="dropdownlist1name"><option value="select">select</option>
<option value="senderid">senderid</option>
</select>
<select id="dropdownlist2name" name="dropdownlist2name" style="display:none"></select><br /><br /><br />
</asp:Content>
Site.master code: add all reference inside header tag
<script type="text/javascript" src="../../Scripts/jquery-1.3.2.js"></script>
<script type="text/javascript" src="../../Scripts/jquery-1.3.2.min-vsdoc.js"></script>
<script type="text/javascript" src="../../Scripts/MicrosoftAjax.js"></script>
<script type="text/javascript" src="../../Scripts/MicrosoftMvcAjax.js"></script>
Here First Dropdownlist is static and jquery is filling second combo onchange of dropdownlist item.
Jquery is not running when get publish on IIS.
Please provide the solution .
Regards
sumit
Mad-Halfling
Participant
1438 Points
729 Posts
Re: jquery/json doesnot work after deployment of asp.net mvc application
Oct 28, 2009 06:20 PM|LINK
Can you try changing the section of javascript
and first see if that works running it from VS, and if so try deploying it please?
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: jquery/json doesnot work after deployment of asp.net mvc application
Oct 28, 2009 09:24 PM|LINK
This is almost always from incorrectly referencing the scripts. Most published samples get this wrong, while it works in
Cassini (AKA Visual Studio ASP.NET development server) - it does't work on the real server.
MVC FAQ
Q: How do I reference scripts?
A: <script src="<%= Url.Content("~/Public/Scripts/RunActiveContent.js") %>" type="text/javascript"></script>
CDN is the best approach:
<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.js" type="text/javascript"></script>
Mad-Halfling
Participant
1438 Points
729 Posts
Re: jquery/json doesnot work after deployment of asp.net mvc application
Oct 29, 2009 08:59 AM|LINK
This point is an extension of what I was saying and is another easy problem to come across in general. As a quick test I also deploy the app to a subdirectory of the document root inetpub/wwwroot on IIS on my machine (so it will be published to http://localhost/apps/<appname> for example) so I can see if the links should work ok in a deployed environment.
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: jquery/json doesnot work after deployment of asp.net mvc application
Oct 30, 2009 01:50 AM|LINK
Good idea. If people would test on IIS before they deploy, they would eliminate these problems.