need help ajex java script

thedigit2s

Well-known member
  • Oct 3, 2009
    2,705
    3,072
    113
    37
    @ katubedda
    දන්න එකෙක් මෙන්න මෙ කොඩ් එක පොඩ්ඩක් එඩිට් කරලා දිපල්ලකෝ..

    දැනට වෙන්නේ මෙ කෝඩ් එක තියෙන පේජ් එකේ ඉදලා එක සැරයක් url එකට දාලා තියෙන xml file එක එක සැරයක් විතරක් ලොඩ් වෙන එක. මට ඔනි setInterval(); function එකෙන් හැම තප්පර 45 කට සැරයක්ම වගේ downloadUrl() කියන function එක call කරවන්න. setInterval(downloadUrl,xxxx); කියලා දුන්නට වැඩක් නැ xml වෙන මොකක් හරි අවුලක් තියෙනවා.
    .:no::no::no::no::no:

    function downloadUrl(url, callback) {

    var request = window.ActiveXObject ?
    new ActiveXObject('Microsoft.XMLHTTP') :
    new XMLHttpRequest;

    request.onreadystatechange = function() {
    if (request.readyState == 4) {

    request.onreadystatechange = doNothing;
    callback(request, request.status);
    }
    };

    request.open('GET', url, true);
    request.send(null);
    }
     
    • Like
    Reactions: EvilEye

    thedigit2s

    Well-known member
  • Oct 3, 2009
    2,705
    3,072
    113
    37
    @ katubedda

    Lakshan-Seram

    Well-known member
  • May 31, 2011
    24,714
    12,619
    113
    127.0.0.1:8080/Kandy
    thanks bro..
    මෙ settimeInterval() function එක වැඩ කරනවා මචෝ මෙකෙන් downloadUrl function එකේන් xml-defined-URL එක page එකට ලොඩ් කරන්නේ එක පාරයි. මට හදා ගන්න ඔනි එකයි
    :):):)

    Server environment before ekakada test karanne? Server one..
     

    sudarakaw

    Member
    Dec 24, 2014
    9
    3
    0
    setInterval(downloadUrl,xxxx); කියලා දුන්නට වැඩක් නැ


    හේතුව
    setInterval function එකට දෙන්න ඕනෙ පළවෙනි argument එක වෙන්න ඕනෙ callback function එකක්‍‍. setInterval මේ callback function එකට call කරන්නෙ කිසිම argument එකක්‍‍ නැතුච, ඒ කියන්‍‍නෙ setInterval(downloadUrl,xxxx) ආකාරයට දුන්නම downloadUrl එකේ තියන url, callback කියන parameter දෙකටම ලැබෙන අගය වෙන්නෙ undefined.

    https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval

    පිලියම
    setInterval එකේ පළවෙනි argument එක හැටියට anonymous/lambda function එකක්‍‍ දෙන්න, ඒක ඇතුලෙ downloadUrl එකට call කරන්‍‍න නිවැරදි argument සමග.

    Code:
    setInterval(function() {
      downloadUrl(yourURLHere, yourCallbackHere)
    }, 45000)

    anonymous/lambda function පාවිච්‍‍චි කරන්න අකමැතිනම් මෙහෙමත්‍‍ කලහැකි:

    Code:
    setInterval(downloadUrl, 45000, yourURLHere, yourCallbackHere)

    හැබැයි මේ ක්‍රමය පරණ IE browser (9 and below) support කරන්නෙෙ නෑ.
     
    • Like
    Reactions: thedigit2s

    thedigit2s

    Well-known member
  • Oct 3, 2009
    2,705
    3,072
    113
    37
    @ katubedda
    හේතුව
    setInterval function එකට දෙන්න ඕනෙ පළවෙනි argument එක වෙන්න ඕනෙ callback function එකක්‍‍. setInterval මේ callback function එකට call කරන්නෙ කිසිම argument එකක්‍‍ නැතුච, ඒ කියන්‍‍නෙ setInterval(downloadUrl,xxxx) ආකාරයට දුන්නම downloadUrl එකේ තියන url, callback කියන parameter දෙකටම ලැබෙන අගය වෙන්නෙ undefined.

    https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval

    පිලියම
    setInterval එකේ පළවෙනි argument එක හැටියට anonymous/lambda function එකක්‍‍ දෙන්න, ඒක ඇතුලෙ downloadUrl එකට call කරන්‍‍න නිවැරදි argument සමග.

    Code:
    setInterval(function() {
      downloadUrl(yourURLHere, yourCallbackHere)
    }, 45000)
    anonymous/lambda function පාවිච්‍‍චි කරන්න අකමැතිනම් මෙහෙමත්‍‍ කලහැකි:

    Code:
    setInterval(downloadUrl, 45000, yourURLHere, yourCallbackHere)
    හැබැයි මේ ක්‍රමය පරණ IE browser (9 and below) support කරන්නෙෙ නෑ.

    ගොඩක් ලොකු රිප්ලයි එකක් දාලා නේද මචෝ.. තැන්ක්ස්. ඔන්න උබව රේප් කරා;)

    හරි මම පහලින් මගේ කොඩ් එක පහලින් දාන්නම්. එකට setinterval funtion eka add කරලා දෙන්න. ලොකු උදවුවක් මචෝ මම කොච්චර ට්‍රයි කරත් හරි යන්නේ නැ. ඇත්තම කතාව මම ජවා ස්කිප්ට් ගැන මෙලෝ හසරක් දන්නේ නැ.. මට මේකේ මැප් එක ලෝඩ් වෙන්නේ නැතිව මකර්ස් ටික විතරක් ලොඩ් කරගන්නයි ඔනි

    <!DOCTYPE html >
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>vtrack</title>
    <style>
    /* Always set the map height explicitly to define the size of the div
    * element that contains the map. */
    #map {
    height: 100%;
    }
    /* Optional: Makes the sample page fill the window. */
    html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    }
    </style>
    </head>

    <body>
    <div id="map"></div>

    <script>
    var customLabel = {
    user: {
    label: 'U'
    },
    bar: {
    customer: 'C'
    }
    };

    function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
    center: new google.maps.LatLng(6.716572137030388, 79.95990197875965),
    zoom: 12
    });
    var infoWindow = new google.maps.InfoWindow;


    // Change this depending on the name of your PHP or XML file
    downloadUrl('mapmarkers2.php', function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName('marker');
    Array.prototype.forEach.call(markers, function(markerElem) {
    var name = markerElem.getAttribute('name');
    var address = markerElem.getAttribute('address');
    var type = markerElem.getAttribute('type');
    var point = new google.maps.LatLng(
    parseFloat(markerElem.getAttribute('lat')),
    parseFloat(markerElem.getAttribute('lng')));

    var infowincontent = document.createElement('div');
    var strong = document.createElement('strong');
    strong.textContent = name
    infowincontent.appendChild(strong);
    infowincontent.appendChild(document.createElement('br'));

    var text = document.createElement('text');
    text.textContent = address
    infowincontent.appendChild(text);
    var icon = customLabel[type] || {};
    var marker = new google.maps.Marker({
    map: map,
    position: point,
    label: type
    });
    marker.addListener('click', function() {
    infoWindow.setContent(infowincontent);
    infoWindow.open(map, marker);
    });


    });

    });
    }



    function downloadUrl(url, callback) {

    var request = window.ActiveXObject ?
    new ActiveXObject('Microsoft.XMLHTTP') :
    new XMLHttpRequest;

    request.onreadystatechange = function() {
    if (request.readyState == 4) {

    request.onreadystatechange = doNothing;
    callback(request, request.status);
    }
    };

    request.open('GET', url, true);
    request.send(null);
    }

    function doNothing() {}
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=&callback=initMap">
    </script>
    </body>
    </html>