• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Javascript question - KeyUp

I have the following code.

The getJson works if it's not placed within the keyup function, but within it, it throws error of 'illegal invocation'. Basically, I have a form in which users can select a custom URL (ie like facebook.com/techboyjk), and as they type in it, I want query if that entry is taken or not. But I'm not sure what's causing the error. Anybody see any issues? I'm kind of at a loss.

works -- >
Code:
     $.getJSON(
		'http://mysite.at/config/cfc/dns.cfc',
			{
				method : 'dnsQuickCheck',
				url : url
			},
			function(result){
				if (result.error == 1) {
					$('#urlExistsError').show();
				}
			}
	);

breaks -->

Code:
$('#url').keyup(function(){
	var checkURL=$(this).val();
	if(checkURL!=''){
	 $.getJSON(
			'http://mysite.at/config/cfc/dns.cfc',
				{
					method : 'dnsQuickCheck',
					url : url
				},
			     function(result){
				if (result.error == 1) {
                                    $('#urlExistsError').show();
					}
				}
		);
	}	
});
 
Last edited:
I'm not sure if this is the cause of your errors but all strings in JSON must use double-quotes.

I think most of the time, single quotes work but I remember there were cases when dealing with events that you had to go strict JSON syntax.
 
I'm not sure if this is the cause of your errors but all strings in JSON must use double-quotes.

I think most of the time, single quotes work but I remember there were cases when dealing with events that you had to go strict JSON syntax.

Thank you for the response. I tried using double-quotes but it yields same error. It's definatley something to do with the getJSON request tho, as if I swap the code with a simple 'alert' pop up, it works fine.
 
I ran your code through JSLint and I didn't see anything that should stop the show, but without being able to actually step through the code, I can't tell you much more.

EDIT: Actually, I thought of something. You are sending the variable 'url' to your endpoint as part of your JSON. Are you declaring 'url' somewhere else? If it isn't, I'd start there because it isn't declared in this bit of code. And if it is, do you have a scoping issue?
 
Last edited:
Where is url defined? Looks to me like you should be passing checkUrl.
 
Where is url defined? Looks to me like you should be passing checkUrl.

Hmm.. URL is defined earlier in the script

Code:
var $url    = $("input[name='url']");

So I was just using that. I guess it's a scoping issue, as using 'url' works fine outside the context of the keyup function.
 
Hmm.. URL is defined earlier in the script

Code:
var $url    = $("input[name='url']");

So I was just using that. I guess it's a scoping issue, as using 'url' works fine outside the context of the keyup function.

Well, a couple of things: first, the text that you want to send to the remote endpoint is assigned to checkUrl in the keyUp handler, so I'm not sure why you wouldn't just pass that. Second, I'm no jquery expert but I don't think '$url' and 'url' are the same thing. You should check and see what the value of 'url' is right before the call to the remote endpoint. It's probably undefined, and that would explain the illegal invocation exception.
 
Second, I'm no jquery expert but I don't think '$url' and 'url' are the same thing. You should check and see what the value of 'url' is right before the call to the remote endpoint. It's probably undefined, and that would explain the illegal invocation exception.

$url and url are definitely not the same thing. And $url would be sending a jQuery object not a string with your value.
 
Back
Top