Orionsbelter Posted July 17, 2016 Share Posted July 17, 2016 I'm trying to create an ajax call using jQuery jsonp. I'm fairly new jQuery and jsonp (trying out some examples to learn), however i'm very keen to learn how to build a javascript file to include into future project that will validate a license code. I'm come up with the following code: <script type="text/javascript" src="http://www.example.co.uk/javascript/jquery/jquery-1.7.1.min.js"></script> <script type="application/javascript"> (function($) { var licensing = function() { var domain = 'test.com'; var EID = 'EXT123'; var LC = '1234'; $.ajax({ type : "GET", dataType : "jsonp", jsonp:"callback", contentType: "application/json", jsonpCallback: "resp", url : "//example.com/license/index.php?domain="+ domain +"&licenseCode="+ LC +"&EID="+ EID +"", success: function(response) { alert(response) }, error: function() { alert('An error occurred during validation. Please try again. If the issue persists, contact support.'); } }); } licensing(null); })(jQuery) </script> However I'm struggling to find suitable examples for the next stage which would be the PHP file example.com/license/index.php which I would like to handle the parameters passed, check the database and create an array named response to hold all the information pulled from the database. I'm fine with connecting to the database, building the array etc but I'm not too sure where to start in regards to accepting the call, I'm tried this simple code for now: <?php $domain = $_GET['domain']; $licenseCode = $_GET['licenseCode']; $EID = $_GET['EID']; echo $domain . " " . $licenseCode . " " . $EID . " "; ?> But It's throwing the error as the AJAX has failed. Does anyone have any good examples of what would need to include the in PHP file to handle the request? Thanks. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 17, 2016 Share Posted July 17, 2016 This is not how JSONP works. Why did you choose it, anyway? JSONP is a horrendously insecure legacy hack. Unless you specifically need to support ancient browsers, use CORS instead. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.