Skip to content

Instantly share code, notes, and snippets.

@MaxXxiMast
Created May 5, 2018 11:28
Show Gist options
  • Save MaxXxiMast/6930bfeface8bc94f49ccec0a870d4b1 to your computer and use it in GitHub Desktop.
Save MaxXxiMast/6930bfeface8bc94f49ccec0a870d4b1 to your computer and use it in GitHub Desktop.
<div><form id="submitform"><input type="text" id="ship-pincode" required maxlength="6" placeholder="Enter Delivery Pincode" name="delivery_pincode" value=""><input type="submit"></form><p id="edd"><span></span></p></div><script>!function(){var e;if(void 0===window.jQuery||"3.3.1"!==window.jQuery.fn.jquery){var t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src","https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"),t.readyState?t.onreadystatechange=function(){"complete"!=this.readyState&&"loaded"!=this.readyState||a()}:t.onload=a,(document.getElementsByTagName("head")[0]||document.documentElement).appendChild(t)}else e=window.jQuery,i();function a(){e=window.jQuery.noConflict(!0),i()}function i(){e(document).ready(function(e){e("#submitform").on("submit",function(t){t.preventDefault(),t.stopPropagation();var a={pickup_postcode:<PICKUP PINCODE>,delivery_postcode:e("#ship-pincode").val(),weight:<WEIGHT OF SHIPMENT IN KGS>,cod:<COD STATUS>};e.ajax({type:"GET",url:"https://apiv2.shiprocket.in/v1/open/courier/serviceability",data:a,success:function(t){if(200==t.status){var a=t.data.available_courier_companies.surface.concat(t.data.available_courier_companies.air),i=a.map(function(e){return parseFloat(e.estimated_delivery_days)}),n=i.filter(function(e){return!isNaN(e)}),o=Math.ceil(Math.max.apply(null,n)),r=Math.ceil(Math.min.apply(null,n));r!==o?e("#edd span").html("Usually delivered in "+r+"-"+o+" days."):e("#edd span").html("Delivery in approximately "+o+" days.")}else 404==t.status&&e("#edd span").html(t.message)},error:function(t){e("#edd span").html(t)}})})})}}();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment