Solved

simple jquery ajax call

Posted on 2008-06-13
10
518 Views
Last Modified: 2010-04-21
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
Comment
Question by:newbie27
  • 7
  • 3
10 Comments
 
LVL 8

Author Comment

by:newbie27
ID: 21778833
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
 
LVL 8

Author Comment

by:newbie27
ID: 21779307
can someone look at this here

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

please help...
0
 
LVL 82

Expert Comment

by:hielo
ID: 21780097
I'll look at this in 50 min or so.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Author Comment

by:newbie27
ID: 21780123
no problem, thanks for looking.
0
 
LVL 8

Author Comment

by:newbie27
ID: 21781156
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
 
LVL 82

Expert Comment

by:hielo
ID: 21781593
>>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
 
LVL 8

Author Comment

by:newbie27
ID: 21781632
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
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21781732
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
 
LVL 8

Author Comment

by:newbie27
ID: 21781800
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
 
LVL 8

Author Closing Comment

by:newbie27
ID: 31466929
thanks
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 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