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

asked on

simple jquery ajax call

Hello Folks,
I am actually doing 2 separate ajax calls from the admin page, one to get the updated <listItems> list from the XML file and get them populated in the SELECT Tag.
and another one on onChange event to pick corresponding or detailed values for the <listname> selected from the recently populated list of the select tag however unable to process.
It seems like I have managed to get appropriate/correct response back but when I wanted to process them to view their details it is getting failed in the viewList() function which I am calling from SELECT onChange.
Please can someone look into the attached and advice/help me.
Your help is much appreciated.
Thanks
Sam





Avatar of newbie27
newbie27
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

And on the admin page
------------------------------

                  
function viewList(sListname){
   
  //if($("#drpLists").val() == 0 || $("#drpLists").val() == "new"){
  if(sListname == 0 || sListname == "new"){
    alert('Please select a list');
  }else{
   
      getListRefs(sListname);      
      var sRefNumbers = $("#listRefnos").val();      
      //$('#defaultResults').hide();
    var sViewQuery = "SF1=keyword&ST1="+sRefNumbers;
      alert(sListname + " : " + sViewQuery);
      $("#listDisplay1").flexigrid       
     ({
        url: 'list_proxy.asp?a=results',      
        colModel : [                                        
                                       {display: '', name : '', width : 30, align: 'left'},            
                        {display: 'Notes', name : 'notes', width : 50, sortable : false, align: 'left'},
           {display: 'Contact    ', name : 'pe_rev_name', width : 150, sortable : true, align: 'left'},
                    {display: 'Compnay Name  ', name : 'co_name', width : 200, sortable : true, align: 'left'},  
                    {display: 'Flag  ', name : 'action_flag', width : 150, sortable : true, align: 'left'},
                    {display: 'Group  ', name : 'co_group', width : 200, sortable : true, align: 'left'}                
        ],
        buttons : [                            
                                {name: 'Delete', bclass: 'delete', onpress : removeFromList},
                                {separator: true}
                                ],                                      
        sortname: '',
        sortorder: 'asc',
        usepager: false,
        title: 'View List Manager',
        useRp: true,
        rp: 100,
        query : sViewQuery+'&Fields=ref_no,notes,pe_rev_name,co_name,action_flag,co_group',        
        showTableToggleBtn: true,                      
        width: 760,
        height: 350,
        onSuccess:function(){
                $(".edit_area").editable( function(value, settings) { return(value); },
                {    
                        submit    : "OK",
                        indicator : "process..........",
                        tooltip   : "Click to edit...",
                           style  : "inherit"
                }
                );
                         
        }
    });  
    //$("#listRefnos").val('');  
  }
 }

--------------
function repopulateList()
{
      $.ajax({
        type: "POST",
        url: "list_builder.asp",
        data: "action=save&listname="+$("#txtListName").val(),
        success: function(msg){
                                          $("#theList").html( msg );                                                
                            }
    });
}


function getListRefs(sListname)
{
      $.ajax({
        type: "POST",
        url: "list_builder.asp",
        data: "action=results&listname="+sListname,
        success: function(msg){                                          
                                          $("#listRefnos").val( msg );                                          
                                          }
      });
}



list-builder.asp
----------------
 
<%
Dim sListName
sListName = Request("listname")
sAction   = Request("action")
sRecord   = "record" 
 
 
If sAction = "results" Then  
    
	'rTxt = showListRefs(sListName)
    Response.write showListRefs(sListName)
	
ElseIf Lcase(sAction) = "save" Then
 
	'rTxt = WriteLMDropDown(sListName)
    Response.write WriteLMDropDown(sListName)
	
End If
 
 
 
'###############################################################################
 
 
Function WriteLMDropDown(sListName)
	
		s9 = "<SELECT name=""drpLists"" id=""drpLists"" onchange=""viewList(document.frmList.drpLists[document.frmList.drpLists.selectedIndex].value);"" style=""width:136px; line-height:18px; padding:0; margin:4px;"">"
   		s9 = s9 & "<OPTION value=""0"">Select List</OPTION>"
		s9 = s9 & WriteListsDropdown(sListName) & "</SELECT>"
		s9 = s9 & "<script>document.frmList.hidList.value=document.frmList.drpLists[document.frmList.drpLists.selectedIndex].value;</script>"
		WriteLMDropDown = s9
		
End Function
 
 
PRIVATE FUNCTION WriteListsDropdown(sKey)
 Dim bound      
    sFilename = "test@test.com.xml"      
    sXMLFile = ADMIN_WWW_FOLDER & "\lists\data\" & sFilename        
       
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
        If fso.FileExists(sXMLFile) Then
                Set oFile = fso.OpenTextFile(sXMLFile)
                xmlData = oFile.ReadAll
                                'response.write xmlData
               xmlListName = split(XMLField(xmlData, "listname", False), chr(28))                       
 
   selectFlag = "SELECTED"
 
    If request.cookies("shortlist") <> "" Then
WriteListsDropdown = WriteListsDropdown & "<OPTION value=""shortlist"" selected> Temp List</OPTION>"
   selectFlag = ""
    End if
                                'on error resume next                           
                                bound = UBound(xmlListName)
                                For i = 0 To bound                              
                                                WriteListsDropdown = WriteListsDropdown & "<OPTION value=""" & xmlListName(i) & """" & " " & selectFlag & ">" & xmlListName(i) & "</OPTION>"
                                       selectFlag = ""
                                Next
        End If
        
        WriteListsDropdown = WriteListsDropdown & "<OPTION value=""new"">New List...</OPTION>"  
 
END FUNCTION
 
 
 
PRIVATE FUNCTION showListRefs(sListName)
    sFilename = "test@test.com.xml"      	
    sXMLFile = ADMIN_WWW_FOLDER & "\lists\data\" & sFilename            
    Set objXML = Server.CreateObject("Microsoft.XMLDOM")
 
	If objXML.load(sXMLFile) Then
		Set objRoot = objXML.documentElement
    End if
 
    Set oNodes = objXML.selectNodes("//lists/*")
   
	count = 1
	For Each oChild In oNodes
	 
		if oChild.childNodes(0).text = sListName Then
		   	showListRefs = oChild.childNodes(2).text 	 
		End if
	Next 
	showListRefs = showListRefs 
 
END Function

Open in new window

can someone look at this here

http://213.253.134.6/artism/admin/list_admin.asp

please help...
Avatar of hielo
I'll look at this in 50 min or so.
no problem, thanks for looking.
If you could please see the list_admin.asp page, you will see I am using script to call flexigrid twice one for the default cookie data and another to view any existing listname,

Can you please amend my code a bit so that I can use it from one function ..?

thanks
>>you will see I am using script to call flexigrid twice
Well, that is not entirely accurately. You are calling it once for #listDisplay and then again for #listDisplay1. They are different elements.
Hielo,
Yes, you are right I am using it for two different TableIDs , can I not use one flexigrid , one function and  pass appropriate parameter to it ?

please advice

thanks

$(document).ready(function(){
    var sRefNos = "";
     var myList = showShortList();
     for(var x=0; x<myList.length; x++){                     
         sRefNos += "," + myList[x].id  ;        
     }
     sRefNos = sRefNos.substr(1);
      
     var sQuery = "SF1=keyword&ST1="+sRefNos; 
    repopulateList();
	
	
     $("#listDisplay").flexigrid
     ({
        url: 'list_proxy.asp?a=results',       
        colModel : [                    
                        {display: ' ', name : 'chkDelete', width : 30, sortable : false, align: 'left'},
						 //{display: '<input type="checkbox" name="chkAll" onclick="checkAll(this.checked)"/> All', width : 30},
                        {display: 'Notes', name : 'notes', width : 50, sortable : false, align: 'left'},
           {display: 'Contact    ', name : 'pe_rev_name', width : 150, sortable : true, align: 'left'},
                    {display: 'Compnay Name  ', name : 'co_name', width : 200, sortable : true, align: 'left'},   
                    {display: 'Flag  ', name : 'action_flag', width : 150, sortable : true, align: 'left'},
                    {display: 'Group  ', name : 'co_group', width : 200, sortable : true, align: 'left'}                 
        ],
        buttons : [                             
                                {name: 'Delete', bclass: 'delete', onpress : test},
								//	{name: 'Select All', bclass: 'add', onpress : test},
									//{name: 'DeSelect All', bclass: 'delete', onpress : test}
                                
                                ],                                      
        sortname: '',
        sortorder: 'asc',
        usepager: false,
        title: 'List Manager - Titles',
        useRp: true,
        rp: 1000,
        query : sQuery+'&Fields=ref_no,notes,pe_rev_name,co_name,action_flag,co_group',         
        showTableToggleBtn: true,                       
        width: 760,
        height: 350,
        onSuccess:function(){
                $(".edit_area").editable( function(value, settings) { return(value); }, 
                {     
						submit    : "OK",
						indicator : "process..........",
						tooltip   : "Click to edit...",
						style  : "inherit",
						callback  : function (value, settings) {
						if ($(this).hasClass('trSelected')) {
                               alert('selected');
                      }
                     }						
                }
                );
				 
        }
    });    
});     
                
				
function viewList(){
    
  var sListname = $("#drpLists").val();
  
  if(sListname == 0 || sListname == "new"){  
    alert('Please select a list');
  }else{
   
	getListRefs(sListname);	
	//alert("listRefnos=" + $("#listRefnos").val());
	var sRefNumbers = $("#listRefnos").val();
	
	 $('#defaultResults').hide();
    var sViewQuery = "SF1=keyword&ST1="+sRefNumbers; 
     // alert(sListname + " : " + sViewQuery);
	$("#listDisplay1").flexigrid	 
     ({
        url: 'list_proxy.asp?a=results',       
        colModel : [                                        
						   {display: '', name : '', width : 30, align: 'left'},		
                        {display: 'Notes', name : 'notes', width : 50, sortable : false, align: 'left'},
           {display: 'Contact    ', name : 'pe_rev_name', width : 150, sortable : true, align: 'left'},
                    {display: 'Compnay Name  ', name : 'co_name', width : 200, sortable : true, align: 'left'},   
                    {display: 'Flag  ', name : 'action_flag', width : 150, sortable : true, align: 'left'},
                    {display: 'Group  ', name : 'co_group', width : 200, sortable : true, align: 'left'}                 
        ],
        buttons : [                             
                                {name: 'Delete', bclass: 'delete', onpress : removeFromList},
                                {separator: true}
                                ],                                      
        sortname: '',
        sortorder: 'asc',
        usepager: false,
        title: 'View List Manager - Titles',
        useRp: true,
        rp: 100,
        query : sViewQuery+'&Fields=ref_no,notes,pe_rev_name,co_name,action_flag,co_group',         
        showTableToggleBtn: true,                       
        width: 760,
        height: 350,
        onSuccess:function(){
                $(".edit_area").editable( function(value, settings) { return(value); }, 
                {     
                        submit    : "OK",
                        indicator : "process..........",
                        tooltip   : "Click to edit...",
                           style  : "inherit"
                }
                );
				 
        }
    });  
    $("#listRefnos").val('');  
  }
 }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna 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
hello hielo,
thanks for your help,
you see for the first call the query i have is different then the Viewlist function ....
both has a unique query ....can we do something for this please?

https://www.experts-exchange.com/questions/23483765/jquery-passing-parameters.html
thanks