Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
HTML
 <script type="application/javascript">
     $(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");
             }

             });
         });
     });
</script>


HTML
<input id="btnUsingjQuery" type="button" value="Test Button" />

below are my code,the logic is after user click on the button,it will lead user Single Entry point Widget for payment,transaction fail or success it will redirect to google.com.But why after i click the button it doesn't lead user to payment page?

What I have tried:

i tried change <script type="application/javascript"> to <script type="application/json"> but still not working..
Posted
Updated 4-Dec-16 1:22am
v3
Comments
Any issues on developer console?

1 solution

A few things to note here, first of all use the following type for script,
JavaScript
<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,
JavaScript
$(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[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900