Link to home
Start Free TrialLog in
Avatar of garethtnash
garethtnashFlag for United Kingdom of Great Britain and Northern Ireland

asked on

JQuery not working!

Help, I have the following JQuery, which is not working...

  $("#PasswordRequestfrm").submit(function(e){
      e.preventDefault();
    $.ajax({
		type: "POST",
        url: "/actions/passwordrequest.asp",
        data:$(this).serialize(),
		success:function(result){
          if(result==2){
            // do something success
     		 $.fancybox.close();
			 location.reload();
          }else {
            // do something fail
			var email = $('#passwordresetinput').val();
	      $('#PasswordResetError').html('<p>Sorry there is no account registered with the username ' + email + '. Please <a class="fancybox" href="#Register" rel="nofollow">register</a> an account to continue</p>');
          $('#PasswordResetError').fadeIn('slow');
          }
  	  }});
  });

Open in new window


The form posting the data is

<form action="" method="post" name="PasswordRequestfrm" class="fancyform" id="PasswordRequestfrm">
  <h3>Password Request</h3>
  <div class="fullbox">
  <div class="notify">Enter your email and click 'Reset password'  we'll email you a link to reset your password.</div>
<div class="alert" id="PasswordResetError" style="display:none"></div>
    <label for="passwordresetinput">Email</label>
    <input name="passwordresetinput" type="email" required="required" id="passwordresetinput" form="Alert" placeholder="e.g joe.bloggs@yahoo.co.uk" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" value="" maxlength="255" />
    <br/>
  </div>
  <div class="fullbox">
  </div>
    <input name="Password Reset" type="submit" disabled="disabled" id="PassReset" form="PasswordRequest" value="Submit" />
  <input name="Cancel" type="button" onclick="$.fancybox.close()" class="cancelbutton closefb" id="PassCancel" form="PasswordRequest" value="Cancel" />
</form>

Open in new window


The remote script is -

<%
if Request("passwordresetinput") <> "" then

Dim CMDPasswordRequest__Username
CMDPasswordRequest__Username = NULL
if(Request("passwordresetinput") <> "") then CMDPasswordRequest__Username = Trim(Request("passwordresetinput"))

set CMDPasswordRequest = Server.CreateObject("ADODB.Command")
CMDPasswordRequest.ActiveConnection = MM_******_STRING
CMDPasswordRequest.CommandText = "dbo.********PasswordRequest"
CMDPasswordRequest.CommandType = 4
CMDPasswordRequest.CommandTimeout = 0
CMDPasswordRequest.Prepared = true
CMDPasswordRequest.Parameters.Append CMDPasswordRequest.CreateParameter("@RETURN_VALUE", 3, 4)
CMDPasswordRequest.Parameters.Append CMDPasswordRequest.CreateParameter("@Username", 200, 1,350,CMDPasswordRequest__Username)
set PasswordRS = CMDPasswordRequest.Execute
PasswordRS_numRows = 0

	If not PasswordRS.eof then
		arrRegister = PasswordRS.GetRows()
	End if

	PasswordRS.Close() 'Clean Up
	Set PasswordRS = Nothing 'Clean Up
	Set CMDPasswordRequest = Nothing 'Clean Up

	Dim result
	
	If IsArray(arrRegister) Then
		dim candlogin 
		For candlogin = 0 to ubound(arrRegister, 2)

			if arrRegister(0,candlogin) = 1 then

				'Response.write(1)
				result = 1

			Elseif arrRegister(0,candlogin) = 2 then
	        	Set myMailApplication=CreateObject("CDO.Message")
				URLShort="this is the subject of a test email second version"
				URLLong="http://*******.co.uk/coms/js/passwordrequest.asp.asp?ID=" + arrRegister(1,candlogin) "&Auth=" +arrRegister(2,candlogin) 
				ReplyMail="*******@******.co.uk"
				ToMail="*******@gmail.com"
				FromMail="""********"" <*******@*******.co.uk>"
		        'Attach=(Server.MapPath(CVAPPLICATION("JBAPCV")))
		        myMailApplication.Subject= URLShort
		        myMailApplication.From= FromMail
		        myMailApplication.To= ToMail
		        myMailApplication.ReplyTo= ReplyMail
		        myMailApplication.CreateMHTMLBody URLLong
		        'myMailApplication.AddAttachment Attach
		        myMailApplication.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
		        myMailApplication.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
		        myMailApplication.Configuration.Fields.Update
		        myMailApplication.Configuration.Fields.Update
		        myMailApplication.Send
		        set myMailApplication=nothing
				result = 2
			end if
		Next
	end If
end if

Response.Write(result)
%>

Open in new window


Appreciate any help you can provide.

Thanks
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

The first thing I would do is either look at the browser console, or remove the jquery and just let the form submit directly to the asp page.  Then you can catch any asp or logic errors.

I have a feeling that is where your issue is and not in the jquery.

On the code below, you don't need to obfuscate the name of the connection string (but no harm doing so) because the username, password and db location is stored in your DW connections.asp file.  However, it would be appropriate to show the CommandText as that is your sql. What I am looking for is if you are using CMDPasswordRequest__Username and how you are using it.
CMDPasswordRequest.ActiveConnection = MM_******_STRING
CMDPasswordRequest.CommandText = "dbo.********PasswordRequest"

Open in new window


Instead of closing the line below with an End If, I would add an Else statement where you set the value of return to something like "No password detected"
if(Request("passwordresetinput") <> "") then CMDPasswordRequest__Username = Trim(Request("passwordresetinput"))

Open in new window


Start with posting the form directly or looking in the browser console and let us know what errors or success you get.
Avatar of garethtnash

ASKER

Hi Scott,

I've made a little progress..

The SP  is --

CREATE PROCEDURE [dbo].[********PasswordRequest
	@Username nvarchar(350)
AS
SET NOCOUNT ON;

/*Declare additional variables */
DECLARE @Result int
DECLARE @UserID NVARCHAR(225)
DECLARE @UserAuth NVARCHAR(225)
DECLARE @UserDetail NVARCHAR(225)


BEGIN

IF NOT EXISTS (SELECT ID from dbo.Candidate where Username = @Username)
BEGIN
SET @Result = '1'
END
ELSE
BEGIN
SELECT @Result = '2', @UserID = ID, @UserAuth = [Password], @UserDetail = HASHBYTES('SHA1', Username) from dbo.Candidate where Username = @Username
END
Select @Result as Result, 
@UserID as UserID, 
@UserAuth as UserAuth,
@UserDetail as Username
End

GO

Open in new window


The SP runs correctly and either returns a 1 or a 2 when run in MSMS.

The JQuery is now posting the data, but the remote script isn't returning anything at all -

%
if Request("passwordresetinput") <> "" then

Dim CMDPasswordRequest__Username
CMDPasswordRequest__Username = NULL
if(Request("passwordresetinput") <> "") then CMDPasswordRequest__Username = Trim(Request("passwordresetinput"))

set CMDPasswordRequest = Server.CreateObject("ADODB.Command")
CMDPasswordRequest.ActiveConnection = MM_******_STRING
CMDPasswordRequest.CommandText = "dbo.********PasswordRequest"
CMDPasswordRequest.CommandType = 4
CMDPasswordRequest.CommandTimeout = 0
CMDPasswordRequest.Prepared = true
CMDPasswordRequest.Parameters.Append CMDPasswordRequest.CreateParameter("@RETURN_VALUE", 3, 4)
CMDPasswordRequest.Parameters.Append CMDPasswordRequest.CreateParameter("@Username", 200, 1,350,CMDPasswordRequest__Username)
set PasswordRS = CMDPasswordRequest.Execute
PasswordRS_numRows = 0

	If not PasswordRS.eof then
		arrRegister = PasswordRS.GetRows()
	End if

	PasswordRS.Close() 'Clean Up
	Set PasswordRS = Nothing 'Clean Up
	Set CMDPasswordRequest = Nothing 'Clean Up

	Dim result
	
	If IsArray(arrRegister) Then
		dim candlogin 
		For candlogin = 0 to ubound(arrRegister, 2)

			if arrRegister(0,candlogin) = 1 then

				'Response.write(1)
				result = 1

			Elseif arrRegister(0,candlogin) = 2 then
	        	Set myMailApplication=CreateObject("CDO.Message")
				URLShort="this is the subject of a test email second version"
				URLLong="http://*******.co.uk/coms/js/passwordrequest.asp.asp?ID=" + arrRegister(1,candlogin) "&Auth=" +arrRegister(2,candlogin) 
				ReplyMail="*******@******.co.uk"
				ToMail="*******@gmail.com"
				FromMail="""********"" <*******@*******.co.uk>"
		        'Attach=(Server.MapPath(CVAPPLICATION("JBAPCV")))
		        myMailApplication.Subject= URLShort
		        myMailApplication.From= FromMail
		        myMailApplication.To= ToMail
		        myMailApplication.ReplyTo= ReplyMail
		        myMailApplication.CreateMHTMLBody URLLong
		        'myMailApplication.AddAttachment Attach
		        myMailApplication.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
		        myMailApplication.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
		        myMailApplication.Configuration.Fields.Update
		        myMailApplication.Configuration.Fields.Update
		        myMailApplication.Send
		        set myMailApplication=nothing
				result = 2
			end if
		Next
	end If
end if

Response.Write(result)
%>

Open in new window


Any other thoughts?

Thanks
What happens if your run the asp code on the server.  Just remove the jquery for now and post directly to the asp code that calls the SP.

For CommandType, I have always included adovbs file and used CommandType = adCmdStoredProc.  Looking at the adovbs file, CommandType = &H0004.  You have, CommandType = 4.  I don't know for sure, but that could be something.

The key is to first make sure your asp page is returning something. At least we know the SP works.
Hi Scott,

OK I've done that, nothing is being written back to the results page...

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Scott,

Managed to find out what the issue was, it was the form, specifically the input element -

<input name="passwordresetinput" type="email" required="required" id="passwordresetinput" form="Alert" placeholder="e.g joe.bloggs@yahoo.co.uk" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" value="" maxlength="255" />

Open in new window


It was referencing the wrong form! - form="Alert"

Thanks for all your help.
I have never used that element before and didn't think about it.  https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input.  The key was no data to the asp page that received the form input.  Good catch.

form
The form element that the input element is associated with (its form owner). The value of the attribute must be an id of a <form> element in the same document. If this attribute is not specified, this <input> element must be a descendant of a <form> element. This attribute enables you to place <input> elements anywhere within a document, not just as descendants of their form elements. An input can only be associated with one form.