Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

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





0
newbie27
Asked:
newbie27
  • 7
  • 3
1 Solution
 
newbie27Author Commented:
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

0
 
newbie27Author Commented:
can someone look at this here

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

please help...
0
 
hieloCommented:
I'll look at this in 50 min or so.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
newbie27Author Commented:
no problem, thanks for looking.
0
 
newbie27Author Commented:
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
0
 
hieloCommented:
>>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.
0
 
newbie27Author Commented:
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

0
 
hieloCommented:
Try:
<script type="text/javascript">
 
$(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();
		listViewer("#listDisplay");
	
});     
                
function listViewer(listID)
{
     	$(listID).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 test(com,grid)
            {
                if (com=='Delete')
					{
						if($('.trSelected',grid).length <= 0){ alert('You have not selected any item.');
						}else{
					   if(confirm('Do you want to delete the selected ' + $('.trSelected',grid).length + ' item(s)?')){
						var items = $('.trSelected',grid);
						var itemlist ='';
						for(i=0;i<items.length;i++){
							//itemlist+= items[i].id.substr(3)+",";	
                        // $(".chkRefNos").checked();				
							removeShortList("shortlist", items[i].id.substr(3));
						}						
						  window.location.reload(true);
						  $("#listDisplay").flexReload();
						
						}}
					}
                else if (com=='Select All'){
						$('.bDiv tbody tr',grid).addClass('trSelected');
				  }else if (com=='DeSelect All'){
						$('.bDiv tbody tr',grid).removeClass('trSelected');
				  }          
            } 
				
 
 
function removeFromList(){
    var result = "";                        
    $(".chkRefNos").each( function () {
      //if(this.checked == true) {             
        removeCookieItem(this);   
     //} 
    });	
	 window.location.reload(true);    
} 
	
				
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);
	listViewer("#listDisplay1");
 
 
/*
	$("#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('');  
  }
 }
</script>

Open in new window

0
 
newbie27Author Commented:
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?

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_23483765.html
0
 
newbie27Author Commented:
thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now