Hi,

In our project I am using ajax with jquery.
here I have applied some code of java script on splitting response which comes from server side.

This code is working fine for small data.

Whenever same application used for large data, script gives problem.
This problem is value is not object due to large data means server takes time to response
and again take time for splitting data here before that processing execute this line

var maxPgno = nxPgNo[nxPgNo.length-1].value;

and it gives error.

script as follows :-

<script>
    
	function  callPage(pgno)
	{
		
			
		var splitData;
		var pageDis;
		var pageNums = "";
		var nextbt = "";
		var disNxt = "";
		var maxPgno1 = "";
		
		//var maxPgno1;//nxPgNo1[nxPgNo.length-1].value;
		//alert(pgHeadVal)
		if(pgno != 1.1)
		{
			
			var nxPgNo1 = document.getElementsByName("btPgNo");
			maxPgno1 = nxPgNo1[nxPgNo1.length-1].value;
			//alert("maxPgno1 = "+maxPgno1);
		}
		$("#disPg").html('<img src="images1/ajax-loader1.gif"> Searching....');
	
   		$.ajax({
			type:"POST",	
			data:"pgno="+pgno+"&maxPage1="+maxPgno1,
			url:"pageSearch.jsp",
	/*		complete: function()
				{
					var prPage = document.getElementById("currentPageId").value
					document.getElementById("currentPageId").value = pgno;
					var nxPgNo = document.getElementsByName("btPgNo");
					alert("nxPgNo = "+nxPgNo.length)
					var maxPgno = nxPgNo[nxPgNo.length-1].value;
					var minPgno = nxPgNo[0].value;
					/*if(pgno==maxPgno1)
						$("#nxtDiv").html("");*/
				
	//				maxPgno++;
				
					//alert("prPage = "+prPage+" and maxPgno = "+maxPgno+" pgno="+pgno);
					//if(prPage!=maxPgno || (prPage!=(minPgno-1)))
	/*				
					if((prPage!=(minPgno-1)))
						if(prPage!=maxPgno )
					document.getElementById(prPage).style.border = "thin solid #006699";
					document.getElementById(pgno).style.border = "thin solid #68056F"; 
				},   
				*/

			success:function(result){
				if(result !=' ')
				{
					//alert(result)	
					splitData = result.split("::");
					pageDis = splitData[0];
					pageNums = splitData[1];
					nextbt = splitData[2].replace(/^\s+|\s+$/g,"");
					
					
						//alert("Click to continue...")
						
						//alert=afterSuccess(pgno);
					

					
					$("#disPg").html(pageDis);
				
					if(pageNums!="")
					$("#disPgNum").append(pageNums);
					
					
					if(nextbt=="nxbt"){
						disNxt = "<input type = \"button\" value=\"Next\" onClick=\"callNextPg()\">";
					}
					$("#nxtDiv").html(disNxt);

		
					afterSuccess(pgno);
						
					

					
			    } 
				
				if(pgno=="1.1")
					pgno = 1;
				
				var prPage = document.getElementById("currentPageId").value
				document.getElementById("currentPageId").value = pgno;
				var nxPgNo = document.getElementsByName("btPgNo");
				//alert("nxPgNo = "+nxPgNo.length)
				var maxPgno = nxPgNo[nxPgNo.length-1].value;
				var minPgno = nxPgNo[0].value;
				/*if(pgno==maxPgno1)
					$("#nxtDiv").html("");*/
			
				maxPgno++;
				
				//alert("prPage = "+prPage+" and maxPgno = "+maxPgno+" pgno="+pgno);
				//if(prPage!=maxPgno || (prPage!=(minPgno-1)))
				
				if((prPage!=(minPgno-1)))
					if(prPage!=maxPgno )
				document.getElementById(prPage).style.border = "thin solid #006699";
				document.getElementById(pgno).style.border = "thin solid #68056F";        

				
			  }
			  
		});
		
		
	}

server side code as follows :-

<%@ page import = "pagination.*"%>
<%@ page import = "java.util.ArrayList"%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");

System.out.println("pageSearch page called");
PaginationSearch pgSrch = new PaginationSearch();


ArrayList list = new ArrayList();

String pageNo = "";
String sendInfo = "";
String pageData = "";
String firstCall = "";
String head = "";
int dotIndex = 0;
int pgNumber = 0;
int len = 0;
list =pgSrch.getList();

int listSize = list.size();
System.out.println("listSize = "+listSize);

if(listSize > 11)
{
	len = 10;
}else{
	len = listSize;
		}
System.out.println("len = "+len);
String pgStr = request.getParameter("pgno");
int maxPage=0;
if(request.getParameter("maxPage1")!="")
maxPage = Integer.parseInt(request.getParameter("maxPage1"));

//String maxPage = request.getParameter("maxPage1");
System.out.println("maxPage="+maxPage);
//maxPage++;

dotIndex = pgStr.indexOf(".");
System.out.println("colIndex = "+dotIndex+" pgStr = "+pgStr);

//int pgNumber = Integer.parseInt(request.getParameter("pgno"));
System.out.println("page number = "+pgNumber);


if(dotIndex == 1)
{
  String secondPara = "<table cellspacing=2 cellpadding=2 border='0'  width=580 align=center><TR class=TDHeadt align=center width='90%'><TD class='blueboldtext'><b>adpdfklsk</b></TD>>";	
  pgNumber = 1;
  for(int i=1;i<=len;i++)
  {	
    	//if(i<=10){
		    		pageNo += "<input type=\"button\" value=\""+i+"\" id=\""+i+"\" name =\"btPgNo\" onClick=\"callPage("+i+")\">";
	      //  	 }
        
		
	//pageNo += "<input type = \"button\" value=\"Next\" onClick=\"callThreadNextPg()\">";
  }
  if(listSize >= 10)
    	pageNo +="::nxbt";
  else
		pageNo +="::";
}else{
	pgNumber = Integer.parseInt(request.getParameter("pgno"));
	//System.out.println("maxPage =="+maxPage);
	if(listSize >= 10 && listSize != maxPage)//&& listSize != maxPage
    	pageNo +="::nxbt";
  else
		pageNo +="::";
}

head = pgSrch.getHeaderData();
pageData = (String)list.get(pgNumber-1);

head += pageData;

sendInfo = head + "::" + pageNo;
System.out.println("pageSearch.jsp sendInfo = "+sendInfo);
response.getWriter().print(sendInfo);

%>

please give me solution .

Thanks in advance

Himmat,

Without running tests, it's hard to see why large data should cause the statement to fail.

By exploiting jquery's inherent tolerance of non-existent elements, you could try replacing lines 91-107 with :

var nxPgNo = $("[name='btPgNo']");
$("#prPage").not(nxPgNo.eq(0)).not(nxPgNo.eq(-1)).css('border', 'thin solid #006699');
$("#pgno").css('border', 'thin solid #68056F');

Unless I have made a mistake, this is equivalent.

There are several other opportunities to simplify your code by using jquery.

Airshow

Sorry, I did make a mistake, replace lines 90-107 with:

var $currentPageId = $('#currentPageId');
var prPage = $currentPageId.attr('value');
$currentPageId.attr('value') = pgno;
var nxPgNo = $("[name='btPgNo']");
$("#"+prPage).not(nxPgNo.eq(0)).not(nxPgNo.eq(-1)).css('border', 'thin solid #006699');
$("#"+pgno).css('border', 'thin solid #68056F');

Airshow

Thank's for giving solution

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.