0

I'm designing a form which will include a captcha code.

I've decided to go with Solve Media to provide this as they offer potential revenue from CAPTCHA codes (see http://www.solvemedia.com/publishers/captcha-type-in).

However, I'm having an issue with my code to display the 'puzzle'

The following code works (which uses body onload="function"

    <html><head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

    $.getScript("https://api-secure.solvemedia.com/papi/challenge.ajax", function() {
    });

});
function showPuzzle(){
    ACPuzzle.create('v3IzWqCqSh23kq5PnRSbVZrYwWlRYBL-', 'acwidget', { lang: 'en', size: 'standard' });      
}   

function submitButton(){
var user_challenge = document.getElementById('adcopy_challenge').value;
var user_response = document.getElementById('adcopy_response').value;



$.ajax({ url: 'libs/shared-functions.php',
    data: {action:'solveCaptchaCode',challenge:user_challenge, response:user_response},
    type: 'post',
    success: function (output) {
        alert(output);
        console.log(output);
    }
});}
    </script>
    </head>
    <body onload="showPuzzle();">
    Puzzle: <br />
    <div id="acwidget"></div>

      <br />  <br />  <br />  <br />
      <button onclick="submitButton()">Submit</button>
    </body>
    </html>

However, when I remove the tage

    <body onload="showPuzzle();">

and change the .ready function to

    $(document).ready(function() {

    $.getScript("https://api-secure.solvemedia.com/papi/challenge.ajax", function() {
        showPuzzle();
    });

});

The error 'ReferenceError: Can't find variable: ACPuzzle' occurs. I've uploaded the failing code to: http://jsfiddle.net/Mhpmf/

Does anybody know of any solutions to this problem?

I need the request to create the puzzle to be made inside the .ready function to integrate with the existing code.

Thanks in advance

4

2 回答 2

1

您可以使用:

window.onload = function() {
    $.getScript("https://api-secure.solvemedia.com/papi/challenge.ajax", function() {
        showPuzzle();
    });
}
于 2012-09-14T16:28:55.650 回答
0

正如@Zathrus Writer 正确所说,

window.onload = function() { ... } 有效。

于 2012-09-14T16:28:00.847 回答