473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Creating portable JS functions containing ajax url calls

228 100+
Alo,

Hope my title is clear...am part of a team that works with CodeIgniter. The HTTP links are in this fashion: www.abc.com/content www.abc.com/content/edit/2

Now, we have some javascsript ajax functions that are shared thru out various sections of the application. One is this:

Expand|Select|Wrap|Line Numbers
  1. function getXtime() {
  2.         var result = "";
  3.         $.ajax({
  4.             type: "GET",
  5.             async: false,
  6.             url: "../tools/getcname",
  7.             data: "{}",
  8.             contentType: "application/json; charset=utf-8",
  9.             dataType: "text",
  10.             success: function (msg) {
  11.  
  12.                 result = msg;
  13.             },
  14.             error: function (jqXHR, textStatus, errorThrown) {
  15.                 result="";
  16.             }
  17.         });
  18.        //alert("returnValue"+paramList);
  19.         return result;
  20.     }
The absolute URL link is www.abc.com/tools/getcname

It works for those urls that are www.abc.com/content format as it the URL is correctly appended. For other format links, it doesn't work as it tries abc.com/content/edit/tools/getcname

We don't want to use absolute URLS as the application will be used in various departments with varioius urls but same website structure.

Is there a short way to solve this?
Dec 21 '15 #1
4 1564
Rabbit
12,516 Expert Mod 8TB
You're not using an absolute URL. This: ../tools/getcname, is a relative URL.
Dec 21 '15 #2
samvb
228 100+
Yes Rabbit, we want relative except it is not working. Absolute paths are uncomfortable as some departments use a different domain and that means for each dept or institution, we have to manually edit the JS before distribution.
Dec 21 '15 #3
gits
5,390 Expert Mod 4TB
so basically it always should translate to:

Expand|Select|Wrap|Line Numbers
  1. [domain]/tools/getcname
? in that case u could use:

Expand|Select|Wrap|Line Numbers
  1. window.location.origin + '/tools/getcname'
if that was what u looking for? in the request spec in JavaScript.
Jan 7 '16 #4
omerbutt
638 512MB
first of all from your code i can see that you are using relative urls for ajax calls not absolute .

Secondly when you say
the application will be used in various departments with varioius urls but same website structure.
i assume that you are trying to say that your application is not hosted on the web and is accessible within the intranet or the local network only, and you have this application hosted on different computers for all the departments and all of them use a separate domain name ?

If Yes then continue reading below

Actually you do not need to be concerned about the domain name you could just remove the
Expand|Select|Wrap|Line Numbers
  1. ../
from your url parameter and what ever domain you or other department is using it will automatically resolve to it if you provide your url parameter as
Expand|Select|Wrap|Line Numbers
  1.  url: "/tools/getcname",
, in this way if you are using
www.abc.com domain then it would send the request to www.abc.com/tools/getcname and if your other department access this application from www.test.com then it would send request to www.test.com/tools/getcname

Hope i made it clear.
regards,
Omer Aslam
Jan 14 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: cmercier | last post by:
Hi everyone! I am using the Prototype library and ran into a serious limitation. I need to make many concurrent AJAX calls to the server, but Prototype is queueing them instead. Obviously,...
9
by: darrel | last post by:
Last week I asked about ASP.net 2.0 AJAX frameworks and there appears to be several to choose from. I haven't used ASP.net 2.0 yet, but from doing a bit of reading, it appears that ASP.net 2.0...
17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
5
by: steve.chambers | last post by:
I'm sure this q must have been asked before but I'm really struggling to find the answer anywhere so have finally given up and will consult the usenet community - hopefully there's someone out...
8
by: Samik R. | last post by:
Hello, I am using the innerHTML property of a div placeholder to update the contents, and the HTML is provided from a perl script on the server side. The perl script gets called through AJAX when I...
3
by: dhsieh | last post by:
I am trying out nested AJAX calls for the first time, but I seem to have hit a snag. The code snippet is the outer AJAX call and a function, it gathers information about a company. As we get towards...
7
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
我们现在遇到一个问题,通过wcf创建的webservice,选择windows service作为宿主,采用java作为客户端调用成功,但是无法使用asp.net ajax调用。...
1
by: kidalex | last post by:
So, I have a summary page of some stuff that gets updated through AJAX calls back to the server every 15 seconds or so. However, if you leave that page up for a few hours - it'll slow down the...
1
by: andwan0 | last post by:
I have a legacy classic ASP website with lots of classic AJAX (many ASP files specially made for processing AJAX requests). We are slowly migrating the website to ASP.NET 2.0 and developing under...
4
by: cppcompiler1000 | last post by:
when i was writing a program in cpp compiler i have got error that " functions containing switch are not expanded inline" what does it mean? please tell me.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.