Link page in ajax function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tiagoc
Forum Newbie
Posts: 1
Joined: Sun May 09, 2010 8:25 am

Link page in ajax function

Post by tiagoc »

Hello everyone , i have problem in pass the link with metod GET with function ajax, the objective is create pagination register in admin page.
http://forum.imasters.uol.com.br/index. ... m-simples/ this sorce code i am use to do pagination

i want pass the link for example:

this link

Code: Select all

echo " <a href=".$_SERVER['PHP_SELF']."?pg=$i_pg2 class=pg><b>$i_pg</b></a> ";
to this function

Code: Select all

javascript:ajaxpage('teste.php','content');"
i am trying to do that but i have erros ,

Code: Select all

$link= "<a href=".$_SERVER['PHP_SELF']."?pg=".($pg+1)."  /a>";
 echo "<a href="javascript:ajaxpage('"$link"','content');" class=pg><b>próximo &raquo;</b></a>";

the function in ajax work in this way :

Code: Select all

var loadedobjects=""
var rootdomain="http://"+window.location.hostname


var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
	var page_request = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
	page_request = new XMLHttpRequest()
	    else if (window.ActiveXObject){ // if IE
			try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
            } 
             catch (e){
                try{
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
                }
                  catch (e){}
            }
      }//else if
                  else
                      return false
                      page_request.onreadystatechange=function(){
                      loadpage(page_request, containerid)
                 }
                        page_request.open('GET', url, true)
                        page_request.send(null)
}//end function

     function loadpage(page_request, containerid){
      if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
      document.getElementById(containerid).innerHTML=page_request.responseText
     }



function loadobjs(){
	if (!document.getElementById)
	return
	for (i=0; i<arguments.length; i++){
	var file=arguments[i]
	var fileref=""
     if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
        if (file.indexOf(".js")!=-1){ //If object is a js file
        fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript");
        fileref.setAttribute("src", file);
        }
          else if (file.indexOf(".css")!=-1){ //If object is a css file
          fileref=document.createElement("link")
          fileref.setAttribute("rel", "stylesheet");
          fileref.setAttribute("type", "text/css");
          fileref.setAttribute("href", file);
          }
    }//end if 
    
         if (fileref!=""){
         document.getElementsByTagName("head").item(0).appendChild(fileref)
         loadedobjects+=file+" " //Remember this object as being already added to page
         }
   }//end for 
}//end function



Regards
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Link page in ajax function

Post by jraede »

What specific errors are you getting? Or, if you don't see any errors, what isn't happening that you want to happen?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Link page in ajax function

Post by cpetercarter »

This bit:

Code: Select all

$link= "<a href=".$_SERVER['PHP_SELF']."?pg=".($pg+1)."  /a>";
 echo "<a href="javascript&#058;ajaxpage('"$link"','content');" class=pg><b>próximo &raquo;</b></a>";
looks strange. As far as I can see, the ajax function wants the url of the new page, not the full html link.
Also, the quotation marks are wrong in the "echo" line. The double quotation mark after 'href=' terminates the string to be echoed. It needs to be "escaped" with a backslash. So does the double quotation mark at the end of the href. Try this:

Code: Select all

$link = $_SERVER['PHP_SELF']."?pg=".($pg+1);
echo "<a href=\"javascript&#058;ajaxpage('$link','content');\" class=pg><b>próximo &raquo;</b></a>";
Post Reply