tags:

views:

46

answers:

3

Hi ,

i am working on cakephp. I have developed an application where i have used localhost in all ajax post and get..

like

                  var ht = $.ajax({
                          type: "GET",
                          url: "http://localhost/FormBuilder/index.php/forms/getInvitees/<?php echo $emailid;?>",
                          async: false
                    }).responseText;


                     var myObject = eval('(' + ht + ')');

this thing works only when i put localhost . But when i change that to my Ip like http://111.11.11.11/FormBuilder/index.php/forms/getInvitees/", then i am getting a syntax error () in the line
var myObject = eval('(' + ht + ')');

WHy it happens ?? Please give valuable suggestions in solving this..

The response for ht will be {"invitees":[{"invitee":"23"}]} from which i will generate a link by

                     var data = myObject;
                 $.map(data.invitees, function(i){ 
                                 var id=i.invitee;

                        $("<a href=<?php echo $link?>/"+id+"/Invitee> <?php echo $link?>/"+id+"/Invitee</a>").appendTo("#"+inc);
                        inc++;                                 

                return i.invitee;});  

Thank you

A: 

You know that localhost translates to 127.0.0.1 in almost any case. Did you make sure to setup your webserver to bind to 111.11.11.11 correctly and serve the same DocumentRoot?

Looks like your not getting a JSON object back when calling the server via IP.

EDIT

I don't know whether or not you are using VirtualHosts to set up your development environment but since you're making use of localhost I will go with Apache's standard httpd.conf.

In the httpd.conf file search for a line that start with Listen .... Make sure that the only line with a Listen directive looks like Listen *:80, to allow Apache to bind itself to any of the IPs available on your machine.

Then, insert the following near the end of the file:

<VirtualHost *>
    ServerName myfoo.com
    ServerAdmin [email protected]
    DocumentRoot "C:/..path to your working directory/"        
</VirtualHost>

Now you have successfully implemented a VirtualHost that serves localhost and any other IP your machine is assigned to from the same DocumentRoot (the directory your HTML/PHP/whatever files reside in).

Good luck.

aefxx
Please share me of how to mention in document root for this IP
Aruna
What kind of web server do you use?
aefxx
i am using apache
Aruna
where will be my httpd.conf file.. I edited the file in my apache2 of etc/apache2 but it didnt reflects anything..
Aruna
Did you restart your server? Changes will only take effect once you restart the server. Looks like you're running Debian/Ubuntu, thus you might want to have a look at http://www.debian-administration.org/articles/101.
aefxx
A: 

Surely using localhost is more generic in this case?

In my CakePHP apps, I use:

'http://localhost/cakeapp/nodeDescriptors/ajaxSetStatus'

or

'/cakeapp/nodes/updateTreeNodes'

for AJAX calls. Remember you'll run into problems if you try to access a different domain directly. Perhaps that is what's happening with your IP-based call?

Leo
A: 

Localhost will only work from your local machine, but mind you, your app will eventually be accessed from out side , where localhost would be the clients machine..

You need to specify the public IP address or the domain name or the network name if you use an internal DNS for an intranet app.


openprojdevel