I hope this question makes sense and I am not missing something obvious.
I have an ASP.NET MVC 3 web application that I have configured to run on IIS instead of Cassini (Project -> Properties -> Web -> Use local IIS webserver). The project URL is http://localhost/myproject.
That works. I can go to the URL and see my application.
As a consequence, when I make an ajax call in JQuery I have to specify the path with a prefix. like this:
$.ajax({
__url: '/myproject/home/verify'__,
type: 'POST',
data: JSON.stringify(x),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: OnVerifySuccess,
error: OnVerifyError
});
When I deploy such an app to AppHarbor say to myapp, I can see the app when I go to
This was surprising to me but I guess that makes sense. You are not really looking at the local deployment configuration.
When I invoke any UI that would cause an ajax call to be made,
it fails with a 404 (not found) for the URL
/myproject/home/verify that the ajax call is using.
Again that makes sense because if you are not deploying to a
myproject folder like I am doing locally, the URL is incorrect.
However when I try the URL without the myproject in it... that is:
http://myapp.ahhpb.com/home/verify
instead of
http://myapp.ahhpb.com/myproject/home/verify
That fails also with a 404.
This may come down to me not understanding how deployment works on your end but it will be be greatly appreciated if you can clarify what might be going on here.
Also if you have any recommendations for how to change URL being used in ajax calls in JQuery on deployment, it will be great.
Thanks
Jaspreet
#1 Posted by friism Support staff on 19 Apr, 2011 04:54 AM
Hardcoding assumptions about your development environment into your code is probably a really bad idea and will tend to always cause headaches when deploying.
If, for some reason, you can't use Cassini, going with IIS Express might be better option.
Having said that, using
Url.Action()/Html.ActionLink()to dynamically generate the ajax url in the view should probably work. Here's an overview of Url Routing with MVC.Let us know if neither of these work out.
friism closed this discussion on 19 Apr, 2011 04:54 AM.
opspark re-opened this discussion on 19 Apr, 2011 05:05 AM
#2 Posted by opspark on 19 Apr, 2011 05:05 AM
You're right. Instead of trying to figure out what the issue might be here, it will be better to insulate the app by using Url.Action() to generate the urls that JQuery will use.
As always, thanks for that tip!
Jaspreet
opspark closed this discussion on 19 Apr, 2011 05:05 AM.
opspark re-opened this discussion on 19 Apr, 2011 05:13 AM
#3 Posted by opspark on 19 Apr, 2011 05:13 AM
An interesting discussion on SO related to this: http://stackoverflow.com/questions/376644/setting-ajax-url-for-jque...
opspark closed this discussion on 19 Apr, 2011 05:13 AM.