I'm having trouble getting the users IP to persist to the next function because every time I call $.getJSON
it skips my function. I am certain that the JSON being returned is fine because when I run the code shown here:
<script type="application/javascript">
$.getJSON("http://www.telize.com/jsonip?callback=?",
function(json) {
document.write("My IP address is : ", json.ip);
}
);
</script>
the IP is written to the screen exactly as you would expect. Here is my most recent attempt:
<script type="application/javascript">
function verifyRecaptchaAnswer() {
var privateKey = 'privateKey';
var challengeValue = $('#recaptcha_challenge_field').val();
var responseValue = "manual_challenge" ;
var userIP = $('#hiddenField').val();
$.post("http://www.google.com/recaptcha/api/verify",
{ privatekey: privateKey, remoteip: userIP, challenge: challengeValue, response: responseValue },
function(data) {
return data;
}
);
}
$(document).ready(function() {
var hiddenField = document.createElement('input');
hiddenField.setAttribute("name", "ipHolder")
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("id", "hiddenField");
$.getJSON("http://www.telize.com/jsonip?callback=?",
function(json) {
hiddenField.setAttribute("value", json.ip);
}
);
$('#submit').on("click", function(){
event.preventDefault();
verifyRecaptchaAnswer();
});
});
</script>
I have tried everything under the sun in that function(json){}
block, but none of it works. Except of course for the example shown on the website, http://www.telize.com/ , which is the first code block posted. I found this site after finding this stack post: How to get client IP address using jQuery, which looks like the same thing. I haven't even gotten to testing the verifyRecaptchaAnswer
function yet, but that is what I want the user IP for.