×

Discussion Board

Results 1 to 8 of 8

Thread: XMLHTTPREQUEST

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    7

    Post XMLHTTPREQUEST

    using javascript console i've found out the following error in my script..

    at line 65:undefined value...what wrong to my code



    var so;
    var imgid_callback1;
    const DIV_ID = 'locationsample';


    function setup(){
    try {
    so = device.getServiceObject("Service.Location", "ILocation");

    }
    catch (e) {
    alert('<setup> ' +e);
    }
    }


    function getLocation(imgId) {


    var updateoptions = new Object();
    // Setting PartialUpdates to 'FALSE' ensures that user get atleast
    // BasicLocationInformation (Longitude, Lattitude, and Altitude.)
    updateoptions.PartialUpdates = false;

    var criteria = new Object();
    criteria.LocationInformationClass = "BasicLocationInformation";
    criteria.Updateoptions = updateoptions;

    try {
    var result = so.ILocation.GetLocation(criteria);
    if(!checkError("ILocation::getLocation",result,DIV_ID,imgId)) {
    document.getElementById(DIV_ID).innerHTML = showObject(result.ReturnValue);
    }
    }
    catch (e) {

    alert ("getLocation: " + e);
    }
    }

    function getLocationAsync(imgId) {
    var updateoptions = new Object();
    updateoptions.PartialUpdates = false;
    var criteria = new Object();
    criteria.LocationInformationClass = "BasicLocationInformation";
    criteria.Updateoptions = updateoptions;

    imgid_callback1 = imgId;

    try {
    var result = so.ILocation.Trace(criteria, callback1);
    if(!checkError("ILocation::getLocationAsync",result,DIV_ID,imgId)) {
    showIMG(imgId,"");
    }
    }
    catch (e) {

    alert ("getLocationAsync: " + e);
    }
    }


    function callback1( result){
    var latitude = result.ReturnValue.Latitude;//<----------------------here is line 65..
    var longitude = result.ReturnValue.Longitude;

    var req = null;
    try {
    req = new XMLHttpRequest();

    if (typeof req.overrideMimeType != "undefined") {
    req.overrideMimeType("text/xml");
    }
    req.onreadystatechange = function() {
    if (req.readyState == 4) {
    if (req.status == 200) {
    }
    } else {
    alert("Error");
    }
    }



    req.open("POST","http://localhost:8080/GPS/location",true);
    req.setRequestHeader("longitude",+longitude);
    req.setRequestHeader("latitude",+latitude);

    req.send();
    } catch (ex) {
    alert(ex);
    }
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: XMLHTTPREQUEST

    Hi,

    you've defined the asynchronous callback with the wrong parameters. It should look like this:
    Code:
    function callback1(transId, eventCode, result)
    {
    ...
    }
    Check out this page for more details:

    http://library.forum.nokia.com/index...57F26C608.html

    Pit

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    7

    Re: XMLHTTPREQUEST

    .i update my code to this:

    function callback1(transId, eventCode, result){
    console.info("getLocationAsync: transId: %d eventCode: %d result.ErrorCode: %d", transId, eventCode, result.ErrorCode);

    var latitude = result.ReturnValue.Latitude;
    var longitude = result.ReturnValue.Longitude;
    -----

    still undefined value at var latitude=result.ReturnValue.Latitude

  4. #4
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: XMLHTTPREQUEST

    Before accessing the Latitude/Longitude values, you should check if there was an error (by using the result.ErrorCode property) and if the event was completed (by checking the eventCode argument).

    Hope it helps,
    Pit

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    7

    Re: XMLHTTPREQUEST

    I add this line:

    var errCode=result.ErrorCode;
    if(errCode){
    alert("(003)GPS Error:"+errCode+""+result.ErrorMessage);
    }
    else{
    alert(result.ReturnValue.Latitude,result.ReturnValue.Longtitude);
    }

    but still..the result variable found undefined..how can i know why my var result found undefined...


    thanks

  6. #6
    Registered User
    Join Date
    Jun 2010
    Posts
    7

    Re: XMLHTTPREQUEST

    what is the use of transId, eventCode,..is it importandin callback function?how can use that parameters?

  7. #7
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: XMLHTTPREQUEST

    Yes, both transId and eventCode are important: you have to check them to identify your call and to be sure that the event is completed. Check out the link I've posted to get more details:

    http://library.forum.nokia.com/index...57F26C608.html

    Pit

  8. #8
    Registered User
    Join Date
    Jun 2010
    Posts
    7

    Re: XMLHTTPREQUEST

    now i know why my var result found undefined..because my send button direct/address to callback function directly..so in callback function the function in getting the value of the variable result in not processing/called..my problem now..where i will address/direct the onclick of the send button?

Similar Threads

  1. Replies: 3
    Last Post: 2010-05-31, 11:43
  2. XMLHttpRequest problem
    By kogan_y in forum Symbian
    Replies: 3
    Last Post: 2009-12-18, 02:46
  3. XMLHTTPREQUEST can cache the content??? Need help
    By alicenan88 in forum Symbian
    Replies: 3
    Last Post: 2009-11-05, 12:02
  4. XMLHttpRequest status always returns NULL
    By vinothg in forum Symbian
    Replies: 6
    Last Post: 2009-09-22, 09:22
  5. XMLHttpRequest statud undefined
    By a.sichel in forum Symbian
    Replies: 12
    Last Post: 2009-05-19, 09:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×