need help in this jquery ajax response
Hi Below is the code i got from internet trying to test but alwys getting false alert event the record does not xist in DB.
Below is the code
<script language="javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#username').blur(function() {
$.ajax({
type: "POST",
url: "checkUser.cfc?method=checkUsername",
data: "username=" + this.value,
datatype: "json",
success: function(response) {
alert(response);
if (response == true) {
alert("true");
//$('#usernameResponse').css('display', 'none');
//$('#submit').attr('disabled','disabled');
} else {
alert("flase");
//$('#usernameResponse').css('display', 'inline');
//$('#username').select();
//$('#submit').attr('disabled','disabled');
} } }); }); });
</script>
<form> <div class="formcontainer">
<label>User Name:</label>
<input type="text" name="username" id="username" />
<span id="usernameResponse">Sorry, that username is taken</span>
</div>
<div class="formcontainer">
<label>Password:</label>
<input type="password" name="password" id="password" />
</div>
<div class="formcontainer">
<input type="submit" id="submit" value="Submit" />
</div>
</form>
CFC File:
<cfcomponent output="false">
<cffunction name="getAllUsernames" access="private" returntype="query" output="false">
<cfset var qGetAllUsernames = queryNew('userID,username') />
<cfset queryAddRow(qGetAllUsernames, 4) />
<cfset querySetCell(qGetAllUsernames, 'userID', 1, 1) />
<cfset querySetCell(qGetAllUsernames, 'userName', 'John', 1) />
<cfset querySetCell(qGetAllUsernames, 'userID', 2, 2) />
<cfset querySetCell(qGetAllUsernames, 'userName', 'Paul', 2) />
<cfset querySetCell(qGetAllUsernames, 'userID', 3, 3) />
<cfset querySetCell(qGetAllUsernames, 'userName', 'George', 3) />
<cfset querySetCell(qGetAllUsernames, 'userID', 4, 4) />
<cfset querySetCell(qGetAllUsernames, 'userName', 'Ringo', 4) />
<cfreturn qGetAllUsernames />
</cffunction>
<cffunction name="checkUsername" access="remote" output="false" returntype="string" returnformat="JSON">
<cfargument name="username" type="string" default="" />
<cfset var qAllUsernames = getAllUsernames() />
<cfquery name="qCheckUsername" dbtype="query">
SELECT * FROM qAllUserNames WHERE upper(username) = <cfqueryparam value="#ucase(arguments.username)#" cfsqltype="cf_sql_varchar" />
</cfquery>
<cfif qCheckUsername.recordcount>
<cfreturn true>
<cfelse>
<cfreturn true>
</cfif>
</cffunction>
</cfcomponent>
when i run cfc alone returns result like true or false but when i try to alert that response alert box of window size with all spaces and rsult comes so not able to tet if(reponse == true does not working.
any help will be great thanks
this is alert box poped with response
true
</td></td></td></th></th></th></tr></tr></tr></table></table></table></a></abbrev></acronym></address></applet></au></b></banner></big></blink></blockquote></bq></caption></center></cite></code></comment></del></dfn></dir></div></div></dl></em></fig></fn></font></form></frame></frameset></h1></h2></h3></h4></h5></h6></head></i></ins></kbd></listing></map></marquee></menu></multicol></nobr></noframes></noscript></note></ol></p></param></person></plaintext></pre></q></s></samp></script></select></small></strike></strong></sub></sup></table></td></textarea></th></title></tr></tt></u></ul></var></wbr></xmp>
