Javascript - JQuery Ajax Url Path Breaks When Accessed In Different Directory Levels?

Oct 15, 2010

Its time for another very simple question that I can't find an elegant solution for. Basically, I have an app that is using a jQuery Ajax call. In this call, you have to specify a URL path for the service that you are calling. In this instance, I am needing to call this JavaScript function from multiple files in my application and those files are on differing levels of the folder structure.

Here's the question, how would you elegantly handle this scenario so that you can call the JS function from any location in your app. Here are my constraints:

1) I am running on Asp.Net 4.0.
2) My current environment has a local, Dev, Test, and Prod Environment (hard-coding the URL path will not work).

Code Snippets:

function MakeTheCall() {
$.ajax({
type: "POST",
url: "Services/FileName.asmx/Handler", //Path in Question
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {
},
error: function(xmlHttpRequest, status, err) {
}
});
}

I would like to be able to call this function (which is in an external JavaScript file) from files in different directory levels, such as:

1) http://SomeDomain.com/SomeDir/CallingFile.aspx
2) http://SomeDomain.com/CallingFile.aspx

View 1 Replies


Similar Messages:

C# - How To Resolve A Javascript Path For Pages That Have Different Directory Levels

Feb 15, 2011

I have a javacript file (script.js, for example) in the following location:

/Website/Shared/Js/script.js

I have two pages which use this javascript, but each one of them seems to require a different path and I can't figure out how to resolve both of them.

One of them is the page:

/Website/One/Two/Three/page.aspx and this requires the path:
<script src="../../../Shared/Js/script.js" type="text/javascript"></script>

The other page is:

/Website/One/Two/page.aspx and this requires the path:

<script src="../../Shared/Js/script.js" type="text/javascript"></script>

I tried to come from the root by doing

<script src="../Shared/Js/script.js" type="text/javascript"></script>

or

<script src="/Shared/Js/script.js" type="text/javascript"></script>

but none of these seem to work. The temp solution I have found is to declare the script twice which is dumb, but that is all I can think of now.

View 2 Replies

Javascript - JQuery Tabs - Using The Cookie Option Breaks GUI

Feb 16, 2011

I've got a tabbed GUI on a webpage using:

JQuery 1.4.2
JQuery-UI 1.8.9 (full download)

The IDs for the 'pane' divs are GUIDs of domain objects in a database. Everything works as it should. But when I include the cookie option in the function call on

$(document).ready(function () {
//$("#tabs").tabs(); //Without tabs works fine
$("#tabs").tabs({ //This call with cookie option breaks everything.
cookie: {
expires: 1
}
});
});

By 'breaks' I mean - the contents of my final tab (which includes a 'submit' button) ends up being displayed at the bottom of every tabbed page although the tab itself looks fine. None of the tabs open the corresponding pane when clicked, but I can see the correct tab id in the address bar on the browser when I click a tab. I've compared the source of both pages (with and without the cookie option) and they are identical apart from the call to the JQuery tab function. But the Javascript console reports an error: cannot call method 'apply' of undefined

Is there something else I need to do to get this to work? The documentation suggests not. I've inluded the cookies plugin as suggested by Nalum, but this hasn't solved the problem. Drilling into jquery-ui-1.8.9.custom.min.js gets me the offending bit of code:

return d.cookie.apply(null,[b].concat(d.makeArray(arguments ...

This code seems to be expecting [b] to be something like ui-tabs-1 which is the way in which the tabs are IDed if you add tabs via the tabs.add(...) function. And of course I don't add my tabs this way - all my tabs have GUID IDs which are related to elements which come from a DB and are output by a Repeater control.
Some HTML below for reference:

<div id="tabs">
<ul>
<li>
<a href='#TabDiv471de30d-aaec-4485-8a50-1b2fdbc58053'>
Tab A
</a>
</li>
<li>
<a href='#TabDiv951e2fee-9272-4a8c-becb-3f3a07770347'>
Tab B
</a>
</li>
</ul>
<div id='TabDiv471de30d-aaec-4485-8a50-1b2fdbc58053'>
This is Pane A
</div>
<div id='TabDiv951e2fee-9272-4a8c-becb-3f3a07770347'>
This is Pane B
</div>
</div>

View 1 Replies

JQuery :: Set Dynamic Image Path In Javascript?

Jul 8, 2010

I am new buddy to Jquery. I am using a Jquery image scroller in ASP.net.But In this scroller image path must be set in javascript like an array. For Ex-Car_Image_Sources=new Array( imagearray// NOTE No comma after last line

View 2 Replies

Web Forms :: Image File Path Breaks When Folder Involved?

Jan 25, 2011

I am building a Web Forms application, it involves a database, so I have some sort of login.

I have put all the webforms to do with Account Login and Update into their own separate folder. The folder is called { Account } in the application root.

My Site.Master is also at the application root, along with other files (e.g. Default.aspx .. etc).

This image file path breaks when I view the pages inside the Account Folder:

[Code]....

I understand why it is happening, but I can't figure out how to avoid this problem, unless I put the Master page along with all the other files into a folder too.

View 2 Replies

Web Forms :: Show Directory List - Url Path is Missing The Directory Name?

Feb 3, 2010

I have a page that shows a list of the files in an upload directory. ie: My customer uploads a file through my web page and the file ends up in the proper directory. When I click on a file name, the url path is missing the directory name. It's as if my customer uploaded directly to my root. Interestingly, when I upload a file through the same web page, the path remains intact and I am able to click on the link and download the file. How can I get the proper path in my url name. Here is my code .

[Code]....

View 1 Replies

JavaScript - Why Are Pages Getting Accessed Synchronously

Mar 3, 2010

I have a Menu page. If a user selects an Menu Item it opens a new IE Window using JavaScript. So user can open different parts of applications in multiple IE Windows. These Windows have the same Session.

My issue is that these pages are accessed synchronously? If one of the child window is waiting for an action to be finished no other request from any other child window is processed. Is it because of using Session variables?

Update: This is only happening to the windows having the same parent. If I have IE child windows from different parent windows then this issue is not there.

View 2 Replies

How To Get Current Page Path In JQuery (while Doing Ajax Call)

Aug 18, 2010

I am doing Ajax call using jQuery and my URL is like

http://localhost;3327/DummyAps/Demo.aspx

In Demo.aspx page i have a WebMethod, which i wanted to call. While doing jQuery ajax call i am giving the URL as "/DemoWebMethod", where "DemoWebMethod" is the Webmethod present in Demo.aspx page.

But while calling the WebMethod it is calling the URL
http://localhost;3327/DummyAps/DemoWebMethod but i want to call
http://localhost;3327/DummyAps/Demo.aspx/DemoWebMethod.

I know that changing the URL from "/DemoWebMethod" to "Demo.aspx/DemoWebMethod" will solve the problem but can i do it without writing that (because i have some problem with that).

View 1 Replies

AJAX :: JavaScript Web Service In Different Virtual Directory?

Mar 18, 2010

I've searched far and wide, but can't find out why this is happening. I have a clientside javascript ajax call into a web service that works fine if both the service and the calling page are in the same directory. If I try to move the web service to another virtual directory, I get this:

Exception type: InvalidOperationException Exception message: Request format is unrecognized for URL unexpectedly ending in '/js'.

Here are the relevant code tidbits for the separate directories attempt.

aspx file:

[Code]....

CallYahooQuotesServiceMethods.js:

[Code]....

asmx file:

[Code]....

I tried this in my web.config, but it didn't work:

[Code]....

Authentication mode is Windows. If I have to impersonate to do this, I'm not sure how I'd pull it off with Javascript.

View 2 Replies

Passing Folder Path String To Web Service Function Via JQuery.ajax?

Apr 24, 2010

I need to perform asp.net web-service function call via jQuery and pass asp.net application path to it. That's the way I'm trying to do it (code is located within asp.net page, e.g. aspx file):

[code]...

Function call works well, but applicationPath parameter doesn't passed correctly. When I debug it I see that backslashes are removed, function gets "C:ProjectsSamplesmytestwebsite" instead of "'C:ProjectsSamplesmytestwebsite'".

View 2 Replies

JQuery :: Return HTML And Javascript From A Jquery Ajax Call

Feb 17, 2011

I have this code being called

[Code]....

which returns <div>here</div><script language=javascript>alert('');</script> The content gets loaded property, but no alert. How would I get a javascript routine to work from an ajax call along with posting the HTML code?

View 4 Replies

AJAX :: How To Create A Menu With Multiple Sub Levels

Feb 22, 2010

I am trying to create a menu with multiple sub levels

Menu 1
Submenu2
SubMenu22

The values of these menus and the urls are populated from the database. Currently I am using a TreeView to achieve this functionality but looks like treeview has lots of overheads.Could you please help me to construct the same functionlity using the accordian and repeater control

View 1 Replies

Adding Javascript From Code Breaks The Validation On Page?

Nov 13, 2010

What I have is button that should open another page only if textbox length is 8. Javascript must be added from code because it does not simply calls the bla.aspx, it's more like bla.aspx?id=4&code=234 etc etc...

I have this code on server side

button.Attributes.Add("onclick","javascript:window.open(bla.aspx)");

on client side i have

<asp:TextBox ID="policyNumberTxt" runat="server" MaxLength="8" CausesValidation="true"></asp:TextBox>
<asp:RegularExpressionValidator ID="policyNumberTxtRev" runat="server"
ControlToValidate="policyNumberTxt" ErrorMessage="Length must be 8."
ValidationExpression="{.{8}.}" ValidationGroup="bla" Display="Dynamic"></asp:RegularExpressionValidator>
<asp:Button ID="printBtn" CssClass="button" Text="Print" runat="server" CausesValidation="true" ValidationGroup="bla" />

What happens is that when I click the button page bla.aspx opens, and even postback is trigered. Validator is showing the message, but page is opened and postback trigered.

How to handle this? Validation is broken...

View 3 Replies

C# - UpdatePanel Breaks JQuery Script - Hide / Show Stuff

Jul 7, 2010

This is a simplified version of what I want to do. Basically I have a datalist with a bunch of stuff in it and when you mouseover items in the datalist I want jquery to hide/show stuff. The problem is that after I databind my gridview/repeater/datalist jquery quits working if the gridview/repeater/datalist is in an update panel. After you click the button in the sample below, the jquery that makes the span show up when you mouse over quits working. Any ideas of why this is happening, how to fix it or a better way to do this?

<script type="text/javascript">
$(document).ready(function() {
$('.comment-div').mouseenter(function() {
jQuery("span[class=mouse-hide]", this).fadeIn(50);
});
$('.comment-div').mouseleave(function() {
jQuery("span[class=mouse-hide]", this).fadeOut(50);
});
});
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="comment-div">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<span class="mouse-hide" style="display: none;">sdfgsdfgsdfgsdfg</span>.......................

View 3 Replies

Disabling Submit Button In Web Application With JavaScript Breaks BlackBerry Submission?

Apr 12, 2010

The following code is being used to disable a Submit button once it has been clicked. This works great on desktop browsers and most BlackBerry mobile browsers.

Submit.Attributes.Add("onclick", "javascript:this.disabled=true;" +
ClientScript.GetPostBackEventReference(Submit, null));

when using a BlackBerry Storm clicking the submit button causes the device to just reload the page. If I remove this code the Storm browser submits the page just fine. I need to disable the button when the browser is capable of doing so but do not want to affect browsers that are not JavaScript capable.

View 2 Replies

MVC :: How To Get Current Directory Path

Jan 30, 2010

I used Directory.GetCurrentDirectory(); and got the following path:

C:Program FilesMicrosoft Visual Studio 9.0Common7IDE

But where I am realy at is c:c#mvcmyProject

How do I get the current directory in a controller not in c:Program Files...?

View 3 Replies

Virtual Directory In IIS To Physical Path

Mar 1, 2010

My basic question is, can a virtual directory in IIS point to a physical path that's not on the local machine? For instance, right now I have a virtual path /NaturalGasReport/NYMEX which points to physical path C:Program Files (x86)NymexSettleNATGAS_REPORTNYMEX, but I want it to point to a physical path on a difference PC on the same network. Is this possible? (I know I can just try it out so I apologize for asking but I thought it would be best to get an explanation along with "yes" or "no"). If you want more detail, this is what I need to do. To make a long story short, because of a vendor product we are using that won't run on a 64-bit operating system, I have to run a program called Generate_NGReportData.vbs (it's a vbscript program) on a PC I will call 28. It uses a vendor product which produces jpg files which are graphs of the Natural Gas market. The machine where I wish it could run is called RTEST01 but this machine runs a 64-bit OS and the components won't work there. RTEST01 has the databases. So, I created a datasource on 28 which points to RTEST01's database. The vbs program will read the data, generate the reports, and write one row to a database table on RTEST01. RTEST01 has to run the complimentary program which sends these reports (via email). 28 is not an email server so it can't email the reports. So on RTEST01 I will run Send_NaturalGasReport.vbs. This program creates an email body of html. The html references [URL]NaturalGasReport/NYMEX/" & Day(nymex_update_dt) & ".jpg which is a virtual directory pointing to C:Program Files (x86)NymexSettleNATGAS_REPORTNYMEX. I need it to point to the folder and files on 28.So if my initial question has a simple yes answer then I am all set. If not, examine my architecture and propose an alternative solution.

View 10 Replies

Configuration :: Why Is The Directory Only Seen When Outside The Root Path

Dec 2, 2010

I'm trying to deploy my web project to my local IIS server (C:inetpubwwwrootlunchbox). By default the in is created inside the project directory - i.e lunchboxin. This setup, however, gives me the following error when I try to open the site:

When I move the in directory outside the project root (i.e C:inetpubwwwrootin), the site opens up just fine. I'm also able to test the web project from Visual Studio without any issues.

Can someone tell me why I have to move the in directory outside the project root to make the site work? What can I do to not have to do this?

View 4 Replies

VB - Simple Directory Path Parsing

Jan 21, 2010

i have a asp.net web application and i need to take a full Directory path (for ex: http:\<server><websitename>folder1 est.lst) and parse the name of the folder that has test.lst file. The directory tree can vary and i just need a generic way to parse this path and find the directory name which has the file.

View 2 Replies

Get The Path To File Using Directory Info?

Jun 1, 2010

I have a page where im listing out the files within a directory. How can i get the path to the files that are listed?

in other words, i want the path to the file to be like this:

http://server.com/files/pdfs/mypdf.pdf

but using this string url = Request.RawUrl.ToString(); returns [ http://server.com/files/pdfs/default.aspxMYPDF.PDF ]

That file is actually within a sub directory of the pdfs folder. So the link is obvisously not correct. Ive tried other suggestions found online, but those return the link like this [ http://server.com/files/pdfs/MYPDF.PDF ] again missing the subdirectory it actually belongs to.

View 8 Replies

Web Forms :: Get Directory Or Folder Name From Path Using C#

Aug 8, 2012

I am using File upload control to upload image and store images in database

When i browse the image

My file path is D:sampleSlide1.JPG

How to i get the folder nameĀ  ie 'sample' from above path?

View 1 Replies

AJAX :: Create AJAX Toolkit Control From JavaScript/jQuery?

Aug 5, 2010

I am wondering if it is possible to create AJAX Toolkit control using JavaScript/JQuery or not. I know that I can create controls at server (at design or code-behind) and interact with its properties using JavaScript but I would rather want to initalize and create controls at client side using JavaScript/JQuery.

View 3 Replies

How Can A Virtual Directory Path Appear Case Sensitive

Nov 18, 2010

To start with then we have a LinkButton whose text is actually an image tag. The image it links to is a Png and resides in a folder in the web directory. This is IIS V6 and win Server 2003.

The path is [URL]

Admin is a virtual directory configured in IIS.

The above url doesn't work but if you change it to [URL] (lowers case 'a') then the image is served, change it back to 'A' and it takes you to login, you log in and it loops back to log in. change to 'a' and voila the image is served. Weirdly this problem doesn't always occur and I have hunted for a resolution for days to no avail.

As requested this is the complete link button

<asp:LinkButton ID="lnkCommitAll" runat="server" CausesValidation="false"><asp:Image ID="imgCommitAll" runat="server" ImageUrl="~/Images/Grid/confirm_16.png" AlternateText="Commit All Changes" /> Commit All</asp:LinkButton>

View 1 Replies

IIS 7 Identify Virtual Directory From Metabase Path?

Nov 17, 2010

I am trying to profile the number of "Anonymous Requests" for an ASP.NET web application using perfmon. When I select this key, I have to pick a process of the form _LM_W3SVC_#_ROOT. How do I map the IIS metabase path back to the web application?

View 1 Replies

Configuration :: Virtual Directory Path Is Not Valid?

Mar 5, 2011

I have created a setup for my application which is having both website and desktop application. i m supposed to changes connection string in both the config files at runtime. i used following code :

[code]...

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved