Please help me on this AJAX code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #16
    and how did you manage to write the AJAX code in the first place?

    Comment

    • kishoreramana
      New Member
      • Feb 2012
      • 4

      #17
      Use the following Code It will work..

      Code:
      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <title>Ajax Demo...</title>
      <style type="text/css">
      .box{border:1px solid black;padding:10px}
      </style>
      <script type="text/javascript">
      var asyncRequest;
      function getContent()
      {
       try
       {
      	 if (window.XMLHttpRequest)
      	  {
      		 asyncRequest=new XMLHttpRequest();
      	  }
      	else
      	  {
      		asyncRequest=new ActiveXObject("Microsoft.XMLHTTP");
      	  }
        //asyncRequest=new XMLHttpRequest();
          asyncRequest.open('POST',"b.html",true);
          asyncRequest.onreadystatechange = stateChange;             
          asyncRequest.send(null);
       }
       catch(exception)
       {
        alert('Request Failed');
       }
      }
      function stateChange()
      {
      	  document.getElementById('contentArea').innerHTML=asyncRequest.responseText;
       if(asyncRequest.readyState==4 ){
         document.getElementById('contentArea').innerHTML=asyncRequest.responseText;
       }
       if(asyncRequest.status==200)
       {
        document.getElementById('contentArea').innerHTML=asyncRequest.responseText;
       }
      }
      function clearContent()
      {
       document.getElementById('contentArea').innerHTML='';
      }
      </script>
      </head>
      <body>
      <h1>Moue over a player for More Information</h1>
      <img src="sachin.jpg" height="42" width="42" onmouseover='getContent()' onmouseout='clearContent()'/>
      <div class="box" id="contentArea"/>
      </body>
      </html>
      Last edited by Rabbit; Feb 14 '12, 04:56 PM. Reason: Please use code tags when posting code.

      Comment

      • sreekandank
        New Member
        • Jun 2009
        • 45

        #18
        Thank You Very Much. Its working well now. What was the mistake done by me?

        Comment

        • kishoreramana
          New Member
          • Feb 2012
          • 4

          #19
          you have not done much mistake..I think in line no 25.
          asyncRequest.op en('POST',"b.ht ml",true); here previously you used 'GET' just i changed it to POST.


          And also for your info if you get any problems while doing with AJAX or with JAvaScript you put alert("message" ) where you get some doubt then easily you can find out the problem what happened.

          Comment

          • sreekandank
            New Member
            • Jun 2009
            • 45

            #20
            Once again thank you very much.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #21
              What was the mistake done by me?
              see post #12
              I think in line no 25.
              asyncRequest.op en('POST',"b.ht ml",true); here previously you used 'GET' just i changed it to POST.
              that's not the reason. if you look at the code you see that there are no parameters used (it's a request for a static page), hence there is no difference between GET & POST.

              Comment

              • kishoreramana
                New Member
                • Feb 2012
                • 4

                #22
                You are right Mr.Dormilich , but when I tried this code in my browser it clearly show the error message method GET is not supported..


                And also without using any webserver how can we send a dynamic URL in asyncRequest.op en('POST',"b.ht ml",true);

                If we use within a server then only we can get the dynamic content..

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #23
                  but when I tried this code in my browser it clearly show the error message method GET is not supported..
                  if GET were not supported, you wouldn't even be able to load a website.

                  And also without using any webserver how can we send a dynamic URL
                  using JavaScript? since you said "send an URL" this comes clearly from the client side so whether or not you use a webserver is irrelevant.

                  Comment

                  • kishoreramana
                    New Member
                    • Feb 2012
                    • 4

                    #24
                    I am talkin about relative URL not the direct URL.. Even we can use a direct URl in html also ...

                    We will Ajax to make our page as asynchronus by using our resources not the websites...

                    And for your info u try the above code with using GET and tell me whether u got the answer or not,,,,

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #25
                      And for your info u try the above code with using GET and tell me whether u got the answer or not,,,,
                      and how should I overcome SOP?

                      Comment

                      Working...