Note that there are some explanatory texts on larger screens.

plurals
  1. POvalidate username ajax and json and asp.net
    primarykey
    data
    text
    <blockquote> <p>Hello,</p> <pre><code>I am trying to verify if a username is taken or available by </code></pre> <p>using jquery to send a request to an asp.net page. The ASP.net page is clearly getting the information as I am having it make an entry into a log database. My SQL server database indeed shows the username being passed to it and is returning a value however for some reason the client side html/javascript doesn't RESPOND to it. I am not sure if it is on the end of my html/javascript or perhaps my asp.net page is not returning the json information correctly? This is my first attempt at json</p> <p>The checking availability box shows up on the html page but it NEVER changes even when the sql server shows that it ran the stored procedure</p> </blockquote> <p>Html File</p> <p></p> <p> <pre><code> $(document).ready(function () { var validateUsername = $('#validateUsername'); $('#username').keyup(function () { var t = this; if (this.value != this.lastValue) { if (this.timer) clearTimeout(this.timer); validateUsername.removeClass('error').html('&lt;img src="images/ajax-loader.gif" height="16" width="16" /&gt; checking availability...'); this.timer = setTimeout(function () { $.ajax({ url: 'ValidateUsername.aspx', data: 'username=' + t.value, dataType: 'json', type: 'get', success: function (j) { validateUsername.html('HI!'); } }); }, 200); this.lastValue = this.value; } }); }); </code></pre> <p>//--> </p> <p> Username, valid: a-z.-_ </p> <pre><code>asp.net page [CheckusernameAvailable.aspx] &lt;%@ Language="C#" AutoEventWireup="true" CodeBehind="CheckUsernameAvailable.aspx.cs" Inherits="Services_UsernameAvailable" %&gt; </code></pre> <p>Asp.net code behind asp.net page [CheckusernameAvailable.aspx.cs]</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using UserSite.DataClasses; using System.Data; namespace OohruWeb { public partial class ValidateUsername : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "application/json"; string NameToLookUp = Request.QueryString["username"]; if (NameToLookUp == null) { NameToLookUp = ""; } DbaseExecSpWithReturnValue Sproc = new DbaseExecSpWithReturnValue(); Sproc.SetSp("sp_CheckUsernameAvailable"); Sproc.AddParam(1); Sproc.AddParam("Username",SqlDbType.Char,NameToLookUp,20); int RetVal = Sproc.Execute(); Sproc.Close(); if (RetVal == 0) { Response.Write(@"'{""success"": false}'"); } if (RetVal == 1) { Response.Write(@"'{""success"": true}'"); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload