Greetings:

I'm beginning to think it isn't possible for CF 9.01 to return JSONP? I am 
using jQuery 1.10.2 on a client to request a JSONP object. See the following 
HTML (client-side):

var jqxhr = $.getJSON( "WeatherFeedJsonp.cfc?callback=?"
       , {method: "get5DayForecastJsonp", latitude: "33.76", longitude: 
"-84.42"}
       , function(data) { loadData(data); } // callback function
       )
       .fail(function(jqxhr, textStatus, error) {
             var err = textStatus + ", " + err; alert(err);
       });

The WeatherFeedJsonp.cfc method get5DayForecastJsonP is coded (server-side):

<cffunction name="get5DayForecastJsonp" access="remote" returntype="array" 
returnFormat="JSON">
       <cfargument name="latitude" type="Numeric" required="true"/>
       <cfargument name="longitude" type="Numeric" required="true"/>

       <cfset var data = get5DayForecastXml(latitude, longitude)/> <!--- 
returns NOAA XML weather feed --->
       <cfset var data = xmlParse(data)/>
       <cfset var xmlRoot = data['dwml']['data']/>
       <cfset var weather = arrayNew(1)/>

<!---
       .
       .
       .
  loop through the XML data variable that contains the 5 day forecast from NOAA
  and create an array of daily weather forecast in the "weather" variable"
       .
       .
       .
--->

       <cfreturn weather/>
</cffunction>

I added

<cfset this.secureJSON = true>
<cfset this.secureJSONPrefix = "// ">

to application.cfc .

On the client, I tested by visiting the URL: 
http://myservername.org/componentName.cfc?method=get5DayForecastJsonp&latitude=...
 And I get a nice looking JSON string back:

// 
[{"ICON":"hi_shwrs50.jpg","LOTEMP":"62","PCTRAINNITE":"48","CONDITIONS":"Chance 
Rain 
Showers","DATE":"2013-12-05","PCTRAINDAY":"54","HITEMP":"72"},{"ICON":"hi_shwrs80.jpg","LOTEMP":"49","PCTRAINNITE":"80","CONDITIONS":"Rain
 Showers 
Likely","DATE":"2013-12-06","PCTRAINDAY":"72","HITEMP":"75"},{"ICON":"ra.jpg","LOTEMP":"47","PCTRAINNITE":"80","CONDITIONS":"Drizzle","DATE":"2013-12-07","PCTRAINDAY":"70","HITEMP":"54"},{"ICON":"ra80.jpg","LOTEMP":"53","PCTRAINNITE":"67","CONDITIONS":"Rain","DATE":"2013-12-08","PCTRAINDAY":"80","HITEMP":"56"},{"ICON":"hi_shwrs70.jpg","LOTEMP":"40","PCTRAINNITE":"49","CONDITIONS":"Rain
 Showers Likely","DATE":"2013-12-09","PCTRAINDAY":"70","HITEMP":"61"}]

But when I execute the code with the $.getJSON call via HTML I get an error. In 
FireBug I get a 200 OK and the data appears as XHR not JavaScript. I know that 
the content type returned in the response must be text/javascript, so I used

<cfcontent type="text/javascript; charset=UTF-8" />

In the CFC component body. The content-type response header says 
"text/javascript", but it still shows up as XHR.

Has anyone implemented a JSONP feed with CF 9? What am I missing?

Sincerely, Brooks
________________________________
Brooks Wilson  |  Senior Web Developer Programmer/Analyst
Technology Solutions Services  |  Application Delivery Services
Federal Reserve Bank of Atlanta  |  1000 Peachtree Street,  Atlanta, GA 
30309-4470
Phone: 404.498.8178 | Fax: 404.498.8239 | Mobile: 404.985.9270
Email: brooks.wil...@atl.frb.org<mailto:brooks.wil...@atl.frb.org>




-------------------------------------------------------------

To unsubscribe from this list, manage your profile @ 

http://www.acfug.org?fa=login.edituserform



For more info, see http://www.acfug.org/mailinglists

Archive @ http://www.mail-archive.com/discussion%40acfug.org/

List hosted by http://www.fusionlink.com

-------------------------------------------------------------


Reply via email to