views:

72

answers:

1

Hi friends,

Requirements :

  1. I have created a html page - to save a group of fields into a separate file

  2. Through ajax function(AjaxLoad), i have send some value into file.php and save it.

  3. I can able to reach the file.php, but its not creating the file.
    code is follows

javascript

function AjaxLoad(LstrXML){
    var xmlhttp;
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
     alert ("Browser does not support HTTP Request");
     return;
    }
    var url="file.php?contentd="+LstrXML;
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,false);
    xmlhttp.send(null);
    function stateChanged()
    {
     if (xmlhttp.readyState==4)
     {
      alert(xmlhttp.responseText);
     }
    }
    function GetXmlHttpObject()
    {
     if (window.XMLHttpRequest)
     {
      return new XMLHttpRequest();
     }
     if (window.ActiveXObject)
     {
      return new ActiveXObject("Microsoft.XMLHTTP");
     }
     return null;
    }
}

php

$fh = fopen("XML/testFile.xml", 'w') or die("can't open file");
$stringData = "<item labelText ='Age' txtBoxSize='20' optionType='*'></item><item labelText ='Gender' txtBoxSize='20' optionType='*'>";
fwrite($fh, $stringData);
fclose($fh);

But its working in all browser's other than IE..What to do for compatibility?
What's the problem in it? Please guide me on this.

Thanks,
Praveen J

+2  A: 

Try changing your 4th line to this would be a good idea:

 var url="file.php?contentd="+ escape(LstrXML)

Also go to your php page in a web browser manually and see if it is outputting valid XML with all tags closed and nested properly.

Sean A.O. Harney
Hi, thanks a lot. now its working fine.. may i know! what is the function of "escape".. why this escape is included here.. thanks again
praveenjayapal
The "escape()" function was deprecated quite a while ago: https://developer.mozilla.org/En/Core_JavaScript_1.5_Guide/Predefined_Functions/Escape_and_unescape_Functions. Use encodeUriComponent instead: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent.
NickFitz
@NickFitz Oh I was unaware of that, thanks for the feedback. I will be sure to use that function instead from now on.@praveen glad it helped, please check out Nick's comment.
Sean A.O. Harney