A few things to note here, first of all use the following type for script,
<script type="text/javascript">
But this is not necessary at all now, browsers are smart enough. You can always omit this and it will work.
Secondly, jQuery code needs to come inside a handler otherwise
$
won't be available, what you wrote is not executed at all (you missed a
()
at the end). Either change your code to meet those standards or do this,
$(document).ready(function () {
$('#btnUsingjQuery').click(function () {
$.ajax({
url: "http://api.google.com/payment/widget?apikey=xxx&country=RS",
dataType: 'json',
success: function (results) {
window.location = 'www.google.com';
},
error: function(){
window.location.replace("www.google.com");
}
});
});
});
This will attach the handler to your element. I didn't tinker with your code, which needs some modifications too.
Finally, if under any case your user is to be navigated, consider using "
complete
" event instead of both success and error case and navigate away from there. If it doesn't work,
please check console of browser.
Make jquery function run on page load - Stack Overflow[
^]
jQuery.ajax() | jQuery API Documentation[
^]