JQuery


#1

I have very little knowledge in this area but I need to implement this.

How would I execute this code from a juce application and return the response.success into variable.

Note: #serial key, #serial_key_uuid, #sku are set in the aplication of course

<script type="text/javascript">// <![CDATA[
        jQuery(function(){
            jQuery("input#validate").on("click", function(){
                jQuery.ajax({
                    url: "http://someaddress.com/?wc-api=validate_serial_key",
                    type: "post",
                    dataType: "json",
                    data: {
                        serial: jQuery("input#serial_key").val(),
                        uuid: jQuery("input#serial_key_uuid").val(),
                        sku: jQuery("input#sku").val()
                    },
                    success: function( response ) {
                        jQuery("p#result").text('');
                        if ( response.success == "true" ) {
                            jQuery("p#result").append( '+response.message+'.' );
                        } else {
                            jQuery("p#result").append( ''+response.message+'.' );
                        }
                    }
                });
            });
        });
// ]]>

 

 


#2

If you're thinking about using the built-in JavascriptEngine class, that will not work. It doesn't implement some fundamental features like closures, so it will not run any non-trivial code.

You can probably write equivalent code directly in C++, using the URL and JSON classes.

--
Roeland


#3

Thank you and initialy I thought of using javascript.

After more research I discovered how to use URL and it works great.