[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

unable to do an ajax call in the second attempt

Hello Experts,
I am doing an Ajax call when the user wanted to view details of selected item from the drop down list.
It is picking up the name, doing the Ajax request and upon appropriate response I am showing the results in the jquery Flexigrid plugin.
Its all seems to be working good in the first attempt, now If I try do the same by selecting some other option from the drop down and when I wanted to view details of this selected item, the result is not been shown in the Flexigrid however I am getting appropriate response back.
Please can some look into this .
Thanks for your help
regards
sam
0
newbie27
Asked:
newbie27
  • 3
1 Solution
 
newbie27Author Commented:
please can someone look into this ?
your help is much appreciated...
thanks
s
on document ready (window onload) I am calling this
 
var sQuery = "SF1=keyword&ST1="+sRefNos; 
repopulateList();
listViewer("#listDisplay" , sQuery);
 
-------------
         
function listViewer(listID, param1)
{		alert(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 : param1 +'&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,viewListCallBack);                
 
   
  }
 }
 
 
function viewListCallBack()
{
    var sRefNumbers = $("#listRefnos").val();
	alert( sRefNumbers)
    $('#defaultResults').hide();
    var sViewQuery = "SF1=keyword&ST1="+sRefNumbers; 
    
        listViewer("#listDisplay1",sViewQuery);
 
}
 
 
function getListRefs(sListname,callBackFunc) 
{ 
        $.ajax({
          type: "POST",
          url: "list_builder.asp",
          data: "action=results&listname="+sListname,
           success: function(msg){
                $("#listRefnos").val( msg );            
                callBackFunc();
          } 
        });
 
}
 

Open in new window

0
 
newbie27Author Commented:
I also have tried without viewListCallBack() function, simply calling by passing parameters ...
please have it  attached and can someone please look into this?

<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", sQuery);
	
});     
                
function listViewer(listID, param1)
{      alert(param1);
     	$(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 : param1+'&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);	
	var sRefNumbers = $("#listRefnos").val();
	
	 $('#defaultResults').hide();
    var sViewQuery = "SF1=keyword&ST1="+sRefNumbers;     
	listViewer("#listDisplay1",sViewQuery);
    
    
    $("#listRefnos").val('');  
  }
 }
 
</script>

Open in new window

0
 
hieloCommented:
in your repopulatelist your ajax response contains the <select> PLUS <script>...</script>. You cannot insert javascript within script tags. You need to extract the content within the <script> tags and use eval (see attached code). Also, this:
var sRefNumbers = $("#listRefnos").val();
var sViewQuery = "SF1=keyword&ST1="+sRefNumbers;

should NOT be executed within viewlist(). It should be executed within the ajax callback function that you have in getListRefs()
 function repopulateList()
{
	$.ajax({
	  type: "POST",
	  url: "list_builder.asp",
	  data: "action=save&listname="+$("#txtListName").val(),
	  success: function(msg)
	  		{
	  			var re = /[<]script[>]([^<]+)[<][\/]script[>]/ig;
				msg.match(re);
				msg = msg.replace(re,"");
				$("#theList").html( msg );								
				eval(RegExp.$1);
			}
	});
}

Open in new window

0
 
newbie27Author Commented:
thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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