If from the page localhost:nnnn/Class I click on an AJAX link that will post to 'Class/AddClass' I get a RawUrl of Class/AddClass and it works just fine.
If from the page localhost:nnnn/Class/Index I click the same link I get a RawUrl of Class/Class/AddClass and it (obviously) doesn't work.
I realize I'm in Routing Hell, but who's rewriting the URL and why? I painstakingly stepped through the jQuery code and indeed it's posting to Class/AddClass.
Thanks for insight...
Eric
It is not rewriting that is the problem. Your AJAX request is JavaScript and has nothing to do with the ASP.NET routing engine. When you use Class/AddClass you are making it relative to the location of the current URL. You can use /Class/AddClass which will resolve to the root of the site. That poses an issue if you are even in a virtual directory. I prefer to pull the full URL from a configuration file:
var url = '<%: ConfigurationManager.AppSettings["WebsiteURL"] %>/Class/AddClass';
With the appropriate entry in the web.config. This eliminates any guess work. You can also use ResolveUrl:
var url = '<%: ResolveUrl("/Class/AddClass") %>';
Related
Because of an HTTP_REFERER issue I need to make a url pass from an https site to http.
I have this bit of javascript but it is not working.
Save this page as PDF
Can I also find out how I would append the current site using javascript their api url?
http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.example.com
Any advice?
Need to block the initial anchor tag event.
Save this page as PDF
I would use either javascript or the href attribute, not both. I don't see how they would work well together.
You can use .preventDefault() as noted, but why put the href attribute there in the first place?
Is this what you're looking for? It should work on both http or https sites.
<a onclick="window.open('http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=' + window.location.href, '_blank', 'location=yes,scrollbars=yes,status=yes');">Save as PDF</a>
I have a MVC application where I have installed umbraco 6.1.6 nuget package.Now I am trying to call a controller from a view using Jquery AJAX function. The controller is placed in MVC controller folder and it is inherited with UmbracoApiController. I have tried to follow the Umbraco API document ,But everytime my request is send it redirects to 404 page. I have tried the same using umbraco 7.1.4 downloaded from here and it works fine for me. Can anyone suggest a solution for this.
The request url I have used is as follows :- /Umbraco/Api/[ControllerName]/[ActionName], I have also tried /Umbraco/[YourAreaName]/[YourControllerName] , but that too doesn't work for me.
Check different things:
reboot the site (touch the web.config)
did you BUILD the code? If you put it in app_code is it picked up automatically, otherwise you need the DLL to be in your bin directory.
what do the log files in /App_Data/Logs tell you?
You can insert your own logs by invoking
LogHelper.Info<myclass>("some message")
are you really really really sure you have not overlooked something from the documentation?
are you sure your controller inherits from UmbracoApiController
have you tried adding [MemberAuthorize(AllowAll = true)] to the api controller or the method?
double check the URL. you probably mistyped the name. The controller is the complete name without "controller". Try the code below to find back the exact url.
The code below came from a usercontrol which i used in a dashboard for the end user. I guess it's pretty easy to convert it into a Razor macro. If this is not returning a thing, you did something wrong from the list above.
var requestHandler = HttpContext.Current.Request.RequestContext;
var urlHelper = new UrlHelper(requestHandler);
var actionlink = Umbraco.Web.UrlHelperExtensions.GetUmbracoApiService<MyApiController>(urlHelper, "MyMethodName");
I am trying to develop a Liferay portlet which will store users preference. This portlet will perform an AJAX call to refresh it content and uses those preferences to fetch data. For this I am using com.liferay.portal.kernel.portlet.DefaultConfigurationAction. Things are working fine if I did not make any changes to Look and Feel.
However when I specify a page to be linked to (Look and Feel -> Link Portlet URL to Page), user settings will be gone and default values will be used instead.
Through debugger I found out that there is no preference found when Look and Feel changes being applied.
Is there a fix for this?
I have managed to fix the problem. It seems that Liferay's IPC does not play well with AJAX.
As mentioned in the question, I set a target URL for this portlet's content to be pointing to. To generate the URL for the AJAX call I use
<portlet:resourceURL var="ajaxResourceURL" />
This tag however generates URL which points to the target URL instead of the current page itself. Thus when an AJAX call being made there is no data as the targetted page does not have the same portlet.
My fix for this is to replace the generated URL's path with the current page's path using javascript.
var url = '<%= ajaxResourceURL %>';
var path = url.substring(url.lastIndexOf("/") + 1, url.indexOf("?"));
var pathname = window.location.pathname;
pathname = pathname.substring(pathname.lastIndexOf("/") + 1, pathname.length);
url = url.replace(path, pathname);
Hopefully this will help those who face the same problem in future.
Hi Folks,
my first post here, thanks for any help i got already throught reading before.
I am working on a wordpress projekt. And it seems i am missing the overview on my problem.
I use ajax to recieve additional product data. http:url/product/additional_ajax_data...
This works fine, except direct call of the ajax urls. Direct call of a ajax url gives
a 404 not found.
Please dont give instructions like: add 200 ok to header... Cause the project will
consist of some thousand pages and work arounds like this are a no go...
Aditional infos: the urls have no ajax hash tag... And the content will dynamicly loaded depending on last url fragment
I found the solution:
To prevent Wordpress of 404 when calling a ajax url directly, add rewrite endpoints to the system.
You can follow the post from Jon Cave on Wordpress:
http://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/
Works also on custom post_types and custom taxonomys, keep an eye on the type for wich you want to register a custom endpoint rewrite (that may depends on your options from your post type, page type etc...).
If you are sure that url is correct and file is there, check if permissions on file are not too strict. Also check .htaccess to make sure it doesn't black certain file extensions to be loaded directly
I have added an MVC3 web application to an existing website that consists of plain old html files. This works great when you request a specific file but what didn't occur to me was that by changing the site to use .Net 4 it no longer took any notice of the default documents setting in IIS (IIS 6 in this case). So for example I can request www.something.com/index.html but if I request www.something.com I get a resource not found error page. Is there a MapRoute in Global.asax I can specify to map the site route url to index.html?
Looks like something has changed, I had to do
routes.IgnoreRoute("");
ASP.NET complained about the route starting with "/"
routes.IgnoreRoute("");
Allows the request to fall through to the default documents defined in the site configuration. I only have a single controller and route in this project that I use for ajax requests from the client. I want the rest of the site to continue to behave as it did when it was just plain html. With routes.IgnoreRoute("") the MVC3 app ignores the request which allows IIS to return the default document. Thanks all for your suggestions.
in global.asax you can try to define a rules like this one
routes.MapRoute("", "index.html", new { controller = "Home", action = "Index" });
But I'm afraid that with IIS 6 you have to handle the Wild card mapping.
That's normal. IIS 6.0 does not support extensionless urls. You will need a wildcard mapping as explained by Phil Haack.