0

I am using application craft as front-end (at application craft server), cakephp as back-end which (installed in localhost- wamp server).

The code below is the part where i used ajax to connect to localhost from application craft:

var params = {name : "madhan",id: 1}; 
app.httpRequest("http://client1.localhost/ezfit-be/users/index",        
      "POST",function(data, error, httpResponse){    
       debugger;
        if (error === false){
          //app.setValue("testlabel", data.results[0].formatted_address);
          alert(data);

      } else {
          alert("Cannot locate it");
     }
    }, params , "json" );

 }
}

However when i run it, it says that unable to connect to the address. I believe that my localhost is not allowing request from another domain.

I tried setting up a virtual host (client1.localhost) but it still gave me the same error

How can i setup my wamp to allow request from other domains?

madi
  • 5,612
  • 5
  • 36
  • 48

1 Answers1

1

If your domain on which you are running the Ajax operation is not same as the domain to which the 'Ajax is accessing`, it won't be possible.

Even if the pointed domain is a sub-domain.

See this article and here, which gives some other options.

Community
  • 1
  • 1
linuxeasy
  • 6,269
  • 7
  • 33
  • 40
  • But in facebook, i tried a locahost connection before using virtual host. This is how web-services work too rite? For example www.foo.com/users/index (has the service that returns the json) and www.xoo.com access using a ajax to (www.foo.com/users/index) and gets the json pattern. – madi Mar 01 '12 at 06:18
  • Webservices work on server-side (languages like PHP, ASP.net), whereas your code is of javascript-ajax, which is a client side. You can proxy your request using your own server communicating the remote server. By this you can make your things work! – linuxeasy Mar 01 '12 at 06:21
  • Yes exactly, the javascript is connecting to a server side to get the json output. The server is hosted locally while the one that request the data is hosted at application craft. My wamp is not allowing access. Do you know how to allow the access? – madi Mar 01 '12 at 06:26
  • Yes, but that server side should be your own server on the same domain, rather than some other remote server :) – linuxeasy Mar 01 '12 at 06:28
  • application craft is a mobile platform and cakephp is the backend that i am using. Both of them are hosted in different host. My database and cakephp is in foo.com (for instance) and application craft is in (xoo.com). Thus xoo.com is accessing the data from foo.com that has the data. Based on my understanding, that is how web-service works. – madi Mar 01 '12 at 06:45
  • @madi: Yes, that understand is absolutely correct! But how does those web-service communicate? they Communicate with a **server-side language** (like php, asp.net, etc) and **not a client-side language like javascript**. You are **disallowed to do it at Client-Side** – linuxeasy Mar 01 '12 at 06:56
  • I am using the client side to access the data from the server side.But since i am developing the system locally, the server side code is hosted in my own wamp server which is localhost. However, the client side is in some cloud based system. Thus when i tried to use the ajax call to connect to my server side it says unknown url. – madi Mar 01 '12 at 07:24