×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    16

    Unhappy HttP Request tsatus 0

    Hii All

    While trying to read from a xml file using ajax i get oReq.status as 0.
    Please help.Here is the code

    var oReq = null;
    function init(){



    try {

    oReq = getXMLHttpRequest();
    if (oReq != null) {
    oReq.open("POST", "file.xml", true);

    oReq.setRequestHeader("Content-type", "text/xml");
    oReq.onreadystatechange = handler;
    oReq.send(null);

    }
    else {
    window.alert("AJAX (XMLHTTP) not supported.");
    }
    }
    catch (ex) {
    alert(ex);
    }
    }


    function getXMLHttpRequest(){
    if (window.XMLHttpRequest) {
    return new window.XMLHttpRequest;
    }
    else {
    try {
    return new ActiveXObject("MSXML2.XMLHTTP.3.0");
    }
    catch (ex) {
    return null;
    }
    }
    }


    function handler(){
    if (oReq.readyState == 4 ) {
    alert("oReq.status" + oReq.status);
    if (oReq.status == 200) {
    var responseXML = oReq.responseText;
    alert(responseXML);
    }
    }
    }

  2. #2
    Registered User
    Join Date
    Mar 2010
    Location
    Zaandam, Holland
    Posts
    71

    Re: HttP Request tsatus 0

    At first glance, it seems like you try to ajax-in a local file 'file.xml' since you
    dont specify a full url.

    Note that local files CAN be retrieved using the xmlhttpobject, but will NEVER EVER return
    a 200 code. While getting a local file, status will be 0 and responsetext will contain something.

    Further,
    I would -not- use window.XMLHttpRequest, instead, conform your way of working:

    function getXMLHttpRequest()
    {
    if (XMLHttpRequest)
    {
    return new XMLHttpRequest();
    }
    else
    {
    try
    {
    return new ActiveXObject("MSXML2.XMLHTTP.3.0");
    }
    catch (ex)
    {
    return null;
    }
    }
    }

    Last thing i noticed, when calling obj.open, try setting the third argument to FALSE when getting local files.

    Good luck.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Location
    Zaandam, Holland
    Posts
    71

    Re: HttP Request tsatus 0

    By the way, you can only use GET methods on local files.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    16

    Re: HttP Request tsatus 0

    Thanks,
    Iam trying to retrieve some info from a file which acts as a property file.You say that you will nor recommend window.XMLHttpRequest.

    than is there any other by which we can read from some property file???

  5. #5
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Perth, Western Australia
    Posts
    286

    Re: HttP Request tsatus 0

    Quote Originally Posted by amitku View Post
    Thanks,
    Iam trying to retrieve some info from a file which acts as a property file.You say that you will nor recommend window.XMLHttpRequest.

    than is there any other by which we can read from some property file???
    Hi,

    I do this all the time with xmlHttpRequests. Here is some of my code which retrieves the group names fom and xml file on the server by running a asp script on the server.

    function get_Groups()
    {
    xmlhttp = null;
    xmlhttp = new window.XMLHttpRequest();
    try {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
    } catch (e) {}
    params = "Mode=findFamily&Name="+MyName+"&Phone="+MyPhone;
    xmlhttp.open("GET", "http://d4072.mysite.westnethosting.com.au/FamilyFinder/FindMyFamily.asp?"+params);
    xmlhttp.send(null);
    xmlhttp.onreadystatechange = stateChangedGroups;
    }

    function stateChangedGroups()
    {
    if (xmlhttp.readyState==4){

    if (xmlhttp.status==200){

    arrayOfGroupsPass = xmlhttp.responseText.split(",");
    arrayOfGroupsPass.length = arrayOfGroupsPass.length-1;
    for (i = 0; i < (arrayOfGroupsPass.length)/2; i++){arrayOfGroups[i] = arrayOfGroupsPass[i]};
    n = -1;
    for (i = (arrayOfGroupsPass.length)/2; i < arrayOfGroupsPass.length; i++){
    n++;
    arrayOfPass[n] = arrayOfGroupsPass[i];
    }

    MyGroup = arrayOfGroups[0];
    MyPass = arrayOfPass[0];
    document.getElementById('f1').value = MyPass;
    document.getElementById('f2').value = MyGroup;
    document.getElementById('f3').value = MyName;
    document.getElementById('f4').value = MyPhone;

    alert(MyGroup+'/'+MyPass);

    groupCount = arrayOfGroups.length;
    if (First){
    //now broadcast my location ......................................
    createTime();
    for (i =0; i < groupCount; i++){
    send_LocationData("Mode=logLocation&newLon="+aLon+"&newLat="+aLat+"&Me="+MyName+"&Time="+dateString+"&Group="+arrayOfGroups[i]+"&Password="+arrayOfPass[i]);

    }
    }
    First = false;
    get_Data();
    }
    }
    }


    I hope this helps.

    Regards
    Brian Oldfield

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    16

    Re: HttP Request tsatus 0

    Thanks,

    I wonder if there is an app server kind of thing in mobile phones.In absence of that status will come as 0.Anyway i was just wondering if local file is in same package why to use Ajax,instead why not put props in .js file and load it at start.
    Last edited by amitku; 2010-04-10 at 20:16.

Similar Threads

  1. Http Post request response
    By anoopd in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2010-02-27, 14:12
  2. Error in Http operation for HEAD request (S40/6230i)
    By elazar.raab in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2010-01-21, 08:34
  3. HTTP Post request structure
    By alav in forum Symbian Networking & Messaging (Closed)
    Replies: 7
    Last Post: 2008-08-12, 10:49
  4. Replies: 1
    Last Post: 2008-02-06, 05:39
  5. How can I call http session simultaneously?
    By gusta72 in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-10-19, 19:58

Posting Permissions

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