News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Need help about Ajax javascript SMF 2

Started by nvcnvn, December 04, 2009, 10:15:10 PM

Previous topic - Next topic

nvcnvn

I writeing amod and need to use ajax, the code just simple is:
<script type="text/javascript">
function ajaxFunction()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
  document.getElementById("n_top_content").innerHTML=xmlhttp.responseText;
  }
}
xmlhttp.open("GET","http://hocvui.net/4rum/n_top.php",true);
xmlhttp.send(null);
}
window.onload = ajaxFunction();
</script>


is there any available the same function script in SMF script help me get a response Text from the other page and put it in to a js variable!?!?!?


Pls help me!

aED

There is a JavaScript function already used by SMF

// Load an XML document using XMLHttpRequest.
function getXMLDocument(sUrl, funcCallback)

That functions fetches XML documents using AJAX

You used it like this:

Quote
var oXMLDoc = getXMLDocument('http://mydomain.com/page-to-xml-document.php');

if (oXMLDoc.responseXML)
{
   //process fetched XML

}

You can also pass another argument the funcCallback which should be a function you created and the function will automatically call that function and will pass the fetched data to that function.

Edit:
BTW I havent tried to fetch a text data using that function since it says that it is used to fetch a XML data. but you can still try if it will work

H

Move to SMF Coding from (SMF 2.x)

Do you still require assistance with this?
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

Advertisement: