Cannot get condition to work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #1

    Cannot get condition to work

    I am returning a string from an ajax call. I want to test if any records were returned. If the server side app does not return any records I load the return string with this code

    Code:
    responseText = {"NoRecord":"No records found"}
    I test for the NoRecord message like this

    Code:
    	
    aString = returnedString.split(";;");
    
    //test if any records were found
    if ( aString.indexOf( 'NoRecord":"No records found' ) != -1 )
    {
      ....process returned records.....
    }else{
      ...display no records returned message...
    	}
    It always evaluates to the no records found condition even when records are returned. I have also tried the reverse where I still got the same result.

    Code:
    	
    aString = returnedString.split(";;");
    
    //test if any records were found
    if ( aString.indexOf( 'NoRecord":"No records found' ) == -1 )
    {
      ...display no records returned message...
    }else{
      ....process returned records.....
    	}
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    I see my problem, aString is an array.
    Code:
    	
    aString = returnedString.split(";;");

    So I got it too work like this.

    Code:
    	
    //test if any records were found
    if ( aString[0].indexOf( 'NoRecord":"No records found' ) != -1 )
    {
       ... display no records found...
    }else{
       ...process records found...
    }

    Comment

    Working...