Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't believe that will work since the service is still returning xml. jsonp is expecting a n object literal as an argument to pass to the callback. I believe if you run this locally you'll realize there's no data being consumable in your success. Try this </p> <pre><code>$.ajax({ type: "GET", url: "http://services.faa.gov/airport/status/IAD?format=json", dataType: "jsonp", success: function (data) { document.myform.result1.value = data.city; }, error: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); } }); </code></pre> <p>Here is the example for creating a proxy with asp.net mvc 3. I just created an action that returns a ContentResult which maps to a string but I define the content type as text/xml. This simply just makes a webrequest to the service and reads the stream in to a string to send back in the response.</p> <pre><code>[HttpGet] public ContentResult XmlExample() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://services.faa.gov/airport/status/IAD?format=xml"); string xml = null; using (WebResponse response = request.GetResponse()) { using (var xmlStream = new StreamReader(response.GetResponseStream())) { xml = xmlStream.ReadToEnd(); } } return Content(xml, "text/xml"); } </code></pre> <p>Your xmlParser function will look like this:</p> <pre><code>&lt;script type="text/javascript"&gt; var result; function xmlparser() { $.ajax({ type: "GET", url: "XmlExample", dataType: "xml", success: function (xml) { result = $(xml).find("City").text(); document.myform.result1.value = result; }, error: function (xml) { alert(xml.status + ' ' + xml.statusText); } }); } &lt;/script&gt; </code></pre> <p>jQuery ajax's converts the data by using $.parseXML internally which removes the requirement for us to even call this in the success block. At that point you have a jQuery object that you can use it's default DOM functions to find the City Node. </p> <p>Make sure to replace the <strong>XmlExample</strong> with the url that it maps to based on your controller.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload