Aloha All,

I have spent a bunch! of time working around what is probably a simple
mistake on my part.

I pass a company name to a CFC using jQuery ajax.  The function in the
CFC checks to see if it exists or not.  It returns the primary key
after insert a new, or retrieves the old, as well as a message.  I
serialize the two values into JSON format and return the result to the
calling jQuery AJAX call. (using SerializeJSON()).

Return WDDX:
<wddxPacket version='1.0'><header></header><data><string>{"new_id":
1,"message":"Company Name already exists"}</string></data></
wddxPacket>

The problem is that the response to the calling page is WDDX, with the
JSON in the <string> node.  I have to parse the wddx XML to find the
JSON string.  I then loop over the object (which has lots in it!!) and
find my little JSON string with two key value pairs, and then use
jQuery parseJSON to get the two values.  This seems like a lot of
work, when I am pretty sure I should be able to refer to the result
with . notation right after I invoke the CFC.

When I change the function returntype to JSON (from string) I get an
error that says the value returned is not of type json.  It definitey
is - I have hardcoded a valid JSON string and returned that with the
same result.

This is BD 1.3 Jetty ready-to-run on Windows XP, SQL Server 2008
Express, Java 6.21.

Am I missing something to force a non-wddx return?

>From the function.
...
<cfset result = Serializejson(result,true,true)>
<cfreturn result />
</cffunction>

Thanks in advance for your attention,

Rob

My embarrassing draft JavaScript:

//jQuery function to update the entry parameters in real time.
Returns a saved message.
        function set_entity(){
                company_name = document.getElementById('Company_Name').value;
                entry_layer_name = 'entity_message';
                document.getElementById('entity_message').innerHTML='';
                //$('##'+entry_layer_name).fadeIn("fast");
                $.ajax({
        url: "/main/Admin/entity_functions.cfc?method=insert_entity",
        type: "POST",
        data: ({company_name : company_name}),
                //error: alert("Trouble..."),
                success: function(msg){
                        parser=new DOMParser();
                        wddxPacket=parser.parseFromString(msg,"text/xml");
                        json_string = 
wddxPacket.getElementsByTagName("string")[0];

                        for (var key in json_string) {
                                var obj = json_string[key];
                                        for (var prop in obj) {
                                        if(prop=='data') {
                                        
//document.getElementById('entity_message').innerHTML += prop + "
= " + obj[prop] + "<br>";
                                        var objson = 
jQuery.parseJSON(obj[prop]);
                                        //alert(objson.message)
                                        }//end if
                                }//end for
                        }//end for
                        
document.getElementById(entry_layer_name).innerHTML=objson.message;
                        
document.getElementById("PK_EntityID").value=objson.new_id
         //
document.getElementById(entry_layer_name).innerHTML='Saved...';
                 // $('##'+entry_layer_name).fadeOut("slow");
      }//end success
                }
                ).responseText;
        }

-- 
Open BlueDragon Public Mailing List
 http://www.openbluedragon.org/   http://twitter.com/OpenBlueDragon
 official manual: http://www.openbluedragon.org/manual/
 Ready2Run CFML http://www.openbluedragon.org/openbdjam/

 mailing list - http://groups.google.com/group/openbd?hl=en

Reply via email to