SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help on Javascript and xml, please help

    After reading wonderful article by Premshree Pillai

    haap://articles.sitepoint.com/article/server-side-xml-javascript
    (replace haap with http)

    I came to know how to handle xml using javascript if the xml is on your server.

    But in the website I'm trying to build, I'm using a service to retrieve xml for each user that views my webpage. Actually I'm trying to access his IP address and then going to find his country.

    browse following link
    haap://ipinfodb.com/ip_query2_country.php?ip=74.125.45.100
    (replace haap with http)

    to this link if you give IP address as parameter, it gives a xml file which contains the country of the user.

    Can someone tell me how can I create an object of XML using this file/url in JavaScript?

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason you can't is due to javascripts same domain policy. You can search for more info.

    What you can do:
    Create a serverside script, for example with php or another language. That script can request the remote url. It basically acts as a proxy, so javascript only needs to request a url on your own server, and then php fetches the content from the other domain.

    You might wanna just skip that other website altogether. You can get free ip to country databases from maxmind and just do it all yourself on your own server.

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is easier to do it on the server side by querying a GeoLocation database like IP2Location or a free web service like FraudLabs. You can always try to do it on the client side using AJAX but if the user has turned off JavaScript or the browser for some reason doesn’t support either JavaScript or AJAX then you will have a big headache.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •