0

I am trying to find a way for xml cross-domain. After googling I found that might be done by jsonp, but I did not get very well the way how it works also after seeing jsonp with jquery and Basic how-to for cross domain jsonp.

I have a pice of html code like following:

<form id="f" name="f" method="POST" action="index.php">
<input type="text" id="t" name="t">
</form>

and in javascript part:

if( typeof (xmlhttp)=="object")
    {
        xmlhttp["open"]("GET",pURL,true);
    }
}

where pURL = index.php?p1="x"&p2="y"

I tried something but it does not work,so I am wondering how I can change the following code to make it correct?

<script>
$.getJSON("http://domainXYZ.com.indexPHP?jsoncallback=?",
  {
    t: "inputValue"
  },
  function(data) {
    $.each(data, function(data){
      alert(data);
    });
  });</script>

Any Idea will be appreciated.

Community
  • 1
  • 1
csuo
  • 820
  • 3
  • 16
  • 31
  • First question: Does the server respond with JSONP? There will be no advantage to getting your client-side right if the server does not supply JSONP responses. You should be able to test by loading the url into a browser window and seeing if you get a response that is designed to use your callback function. – Scott Sauyet Jul 25 '12 at 11:46
  • Thanks for your comment, I tried following url in the browser: http://www.domainXYZ.com/abc.aspx?Code=XYZjsoncallback=? and I see the page, does it mean that the server respond with JSONP? – csuo Jul 25 '12 at 11:54
  • A JSONP response will look like `yourCallbackName({"some": "json"});` instead of simply `{"some": "json"}`. `yourCallbackName` would replace the `?` in the url. – Scott Sauyet Jul 25 '12 at 12:00
  • I did not get your point, for example for following url I just see the script: http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=? – csuo Jul 25 '12 at 12:10
  • 1
    As far as I can tell, that URL supplies an RSS feed, no JSON at all. You're not going to parse XML with a JSON parser. – Scott Sauyet Jul 25 '12 at 12:31
  • Look at the difference between [a plain json](http://api.wikilocation.org/articles?lat=51.500688&lng=-0.124411&limit=1) and [a jsonp](http://api.wikilocation.org/articles?lat=51.500688&lng=-0.124411&limit=1&jsonp=handleArticles) request to the wikilocation api. – Scott Sauyet Jul 25 '12 at 12:50

0 Answers0