[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Why won't this work?

Posted on 2011-10-14
12
Medium Priority
?
364 Views
Last Modified: 2013-12-25
Probably very silly but I cant make this work,   I am doing an ajax query to the database and if the criteria, in this case last name, come back with multiple rows my responsetext is there are multiple clients.    It is being returned.  I just want to do a simple evaluation if it comes back with 1 name process it normally if there are multiples I have to populate a pick list.  

the attached code is what has me frustrated  The string is returned correctly each time.

Thanks
function handleStateChange() {                                 
   if (xmlHttp.readyState == 4) {                              
      if (xmlHttp.status == 200) {    
   var retSTR =" ";
   var retSTR = xmlHttp.responseText;
	  if (retSTR === "There are multiple Clients"){
        alert(retSTR);  }
		 }else{	                      	   	
	 parseResults(); }
      }                                                        
   }                                                                                                               
}

Open in new window

0
Comment
Question by:Charlietn
  • 6
  • 6
12 Comments
 
LVL 41

Expert Comment

by:HonorGod
ID: 36969953
> I am doing an ajax query to the database ...

  So, you are actually having your Ajax request sent to a server side application that is actually executing the DB query... right?

  Is the callback routine being called?
function handleStateChange() {                                 
   if (xmlHttp.readyState == 4) {                              
      if (xmlHttp.status == 200) {
          var retSTR = xmlHttp.responseText;
          alert( 'status 200: "' + retSTR + "' )
	  if ( retSTR === "There are multiple Clients") {
              alert(retSTR);  }
          } else {	                      	   	
              parseResults();
          }
      }                                                        
   }                                                                                                               
}

Open in new window

0
 

Author Comment

by:Charlietn
ID: 36970049
Yes,  the server returns the string and all works well.   parseResults() handles the split and fills in the fields.    If the query returns more than 1 row I return the morethanone string.  If it comes back as "There are multiple Clients" I need to allow the user to select from a list.  If it does not come back I need parseResults to execute

THanks.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36970354
So, you need to decide how to respond to the "There are multiple Clients" returned result?

I would consider having a portion of the page used to display the "multiple results", and allow the user to select the one(s) to be processed.

What, exactly, are you looking for with this question?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Charlietn
ID: 36970381
I cant get the if statement to work.
if ( retSTR === "There are multiple Clients") {
              alert(retSTR);  }
          } else {	                      	   	
              parseResults();

Open in new window

0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36970428
Are you seeing an alert dialog box generated by this statement?

If so, please add a copy of the dialog box here for our review.

Thanks
alert( 'status 200: "' + retSTR + "' )

Open in new window

0
 

Author Comment

by:Charlietn
ID: 36970503
No Sir.   I just need to evaluate the returned string and act on it  That is what is failing.  the alert (retStr) is there only for me.  It will be relaced by another function.  

When my string is returned from the server it DOES contain "There are multiple clients"  but it does not trigger the alert.  When I get the If statement to work if the returned string contains "There are multiple clients"  I want to run a function.  If it does not contain "There are multiple clients" I want parseResults to run.  

if string contains ""There are multiple clients"
  do this
if it does not contain "There are multiple clients"
 do that

right now when the return string contains "There are multiple clients" the alert does not fire.  I assume there is something wrong with my if statement.

Thanks

 
function handleStateChange() {                                 
   if (xmlHttp.readyState == 4) {                              
      if (xmlHttp.status == 200) {
          var retSTR = xmlHttp.responseText;
	  if ( retSTR === "There are multiple Clients") {
              alert(retSTR);  }
          } else {	                      	   	
              parseResults();
          }
      }                                                        
   }                                                                                                               
}

Open in new window

function handleStateChange() {                                 
   if (xmlHttp.readyState == 4) {                              
      if (xmlHttp.status == 200) {
          var retSTR = xmlHttp.responseText;
	  if ( retSTR === "There are multiple Clients") {
              alert(retSTR);  }
          } else {	                      	   	
              parseResults();
          }
      }                                                        
   }                                                                                                               
}

Open in new window

function handleStateChange() {                                 
   if (xmlHttp.readyState == 4) {                              
      if (xmlHttp.status == 200) {
          var retSTR = xmlHttp.responseText;
	  if ( retSTR === "There are multiple Clients") {
              alert(retSTR);  }
          } else {	                      	   	
              parseResults();
          }
      }                                                        
   }                                                                                                               
}

Open in new window

0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36970545
If the alert does not fire, then the string you are expected is not what is present.

That is why I suggested that you add the alert() in line 5 here: http://e-e.com/Q_27397345.html#a36969953

This alert should be generated when the status is 200 (i.e., "OK").

If you aren't seeing this alert dialog box, then we should add an alert showing:

- handleStateChange() is being invoked
- xmlHttp.readyState has a value of 4

Does this make sense?
0
 

Author Comment

by:Charlietn
ID: 36970561
The string is present.  If I just put the alert in without the if statement it fires and shows "There are multiple clients"   That is why I am questioning the if statement.

Thanks
function handleStateChange() {                                 
   if (xmlHttp.readyState == 4) {                              
      if (xmlHttp.status == 200) {
          var retSTR = xmlHttp.responseText;
	 alert(retSTR);  }
               }                                                        
   }                                                                                                               
}

Open in new window

0
 
LVL 41

Accepted Solution

by:
HonorGod earned 500 total points
ID: 36971040
The reason that I suggested using something like the code below, is so that we can see exactly where the double quotes appear.

Be on the lookout for output something like this, where the trailing double quote appears on the next line.
This indicates that a newline character is present in the string.

Another possibility is that there are leading / trailing spaces...

This too would be seen when we surround the string in quotes.
alert( 'status 200: "' + retSTR + "' )

Open in new window

"There are multiple Clients
"

Open in new window

0
 

Author Comment

by:Charlietn
ID: 36971351
OK.  Thanks.  I will try it and let you know

Charlie
0
 

Author Closing Comment

by:Charlietn
ID: 36975943
returnedString.match

Worked

Thanks
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 36978773
Super.  I'm glad to be able to help.

Good luck & have a great day.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question