Solved

Handling XML response after sending HTML Post to URL

Posted on 2010-09-04
39
1,422 Views
Last Modified: 2012-05-10
Below is a page on my website which is authenticated for users that I send to a vendor for freight rates. After I fill the following values:

17545
21014
100
500

I get directed to a different page (.PHP)  showing the xml data that I expect, but I cannot do anything with the page.

I need to  know how to collect that data so I can manipulate it to variables.

Can someone explain what code to use and exactly where to place it either in the VB source page or in the aspx page?


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="xmltest.aspx.vb" Inherits="xmltest" AspCompat="true"  %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    </form> 

<form action=http://www.pngbtob.com/webrater.php method=post>

<input type=hidden name=custdata value="421">

<input type=hidden name=wid value=4>

<input type=hidden name=wid2 value=7176640500>

 

<table>

<tr>

	<td>Origin Zip</td>

	<td>

	<input type=text name=origin value=>

	</td>

</tr>

<tr>

	<td>Destination Zip</td>

	<td>

	<input type=text name=dest value=>

	</td>

</tr>

<tr>

	<td>Class Product 1</td>

	<td>

	<input type=text name=class1 value=>

	</td>

</tr>

<tr>

	<td>Weight Product 1</td>

	<td>

	<input type=text name=weight1 value=>

	</td>

</tr>



 

<tr>

	<td colspan=2>

	<input type=submit name=btnSubmit value="ANY VALUE">

	</td>

</tr>





</table>

       

            

    </form>







</body>





</html>

Open in new window

0
Comment
Question by:Smummery
  • 17
  • 12
  • 6
  • +2
39 Comments
 
LVL 7

Expert Comment

by:wdfdo1986
Comment Utility
did u tried to access them using input field names?
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
Hi, for starters your going to want to PROXY the form POST via some code, either client side JavaScript, or VB / ASP code Server side, so alter the form "action" below to either a NEW page on your on site or a JavaScript function name in your document:

<form action=http://www.pngbtob.com/webrater.php method=post>

As to what the code should look like, there's a wealth of example ASP Web Service and Client side Ajax code out on the Web, that could be adapted in a few min's e.g.

http://www.daniweb.com/forums/showthread.php?t=30083&highlight=asp+parse+xml+response&page=3
http://msdn.microsoft.com/en-us/library/ms757849%28VS.85%29.aspx
http://www.codedigest.com/Articles/ASPNET/342_Using_XPath_Expression_to_Access_or_Read_XML_document_in_ASPNet.aspx
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
0
 
LVL 7

Expert Comment

by:wdfdo1986
Comment Utility
when you post the form the input values will be posted with the keys of the input field names. So u can access them from the other side. Doesn't matter what is the server technology is?
0
 
LVL 3

Expert Comment

by:moonlight
Comment Utility
well, you can't use their page as the action in your form. You need to make your own page get entries from the form, and from within your vb code, send it to their server, then retrieve the xml, parse it, manipulate it, and then send it out as response to the user...

to parse the xml response, you use xmldom in preferably msxml6.dll

for a basic form parsing in asp.net see:
http://articles.sitepoint.com/article/net-form-processing-basics/2

for parsing xml see:
http://msdn.microsoft.com/en-us/library/aa468547.aspx
0
 

Author Comment

by:Smummery
Comment Utility
I am using the code they gave me from my page...it redirects the xml to another page...i am not sure how to get it back.
0
 

Author Comment

by:Smummery
Comment Utility
When I send the post from web site using the above code it comes back to me from their page and I cannot manipulate the data. I need some examples of code that would do this?
0
 
LVL 3

Expert Comment

by:moonlight
Comment Utility
Just check out the tutorials, they have the examples... :)
0
 

Author Comment

by:Smummery
Comment Utility
I have read them before...guess where I am not getting it is how to send the request and manipulate it...the returned page wont let me modify.
0
 

Author Comment

by:Smummery
Comment Utility
Can you try pasting my code and see what returns and then offer some sample code to direct the page to somewhere that I can work with it?
0
 

Author Comment

by:Smummery
Comment Utility
i read up on the parsing xml article and added the following code to page load but ot no avail. the PHP return page ignores the page.

Any thoughts?

Imports System.Xml


Partial Class xmltest
    Inherits System.Web.UI.Page

   

   
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If IsPostBack Then

            Const URLString As String = "http://www.pngbtob.com/webrater.php"
            Dim reader As XmlTextReader = New XmlTextReader(URLString)
            Do While (reader.Read())
                Select Case reader.NodeType
                    Case XmlNodeType.Element 'Display beginning of element.
                        Console.Write("<" + reader.Name)
                        If reader.HasAttributes Then 'If attributes exist
                            While reader.MoveToNextAttribute()
                                'Display attribute name and value.
                                Console.Write(" {0}='{1}'", reader.Name, reader.Value)
                            End While
                        End If
                        Console.WriteLine(">")
                    Case XmlNodeType.Text 'Display the text in each element.
                        Console.WriteLine(reader.Value)
                    Case XmlNodeType.EndElement 'Display end of element.
                        Console.Write("</" + reader.Name)
                        Console.WriteLine(">")
                End Select
            Loop

        End If



    End Sub
End Class
0
 
LVL 3

Expert Comment

by:moonlight
Comment Utility
this line: form action=http://www.pngbtob.com/webrater.php method=post

tells the html page to post to their server. you need to post to your own page.

then you seem to have an empty form above it that seems much more asp like:
id="form1" runat="server

better to use that one only.
0
 

Author Comment

by:Smummery
Comment Utility
The url is required because that is the server URL where the information NEEDS to come from. How else would you suggest that I do it?
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
Per my post above (33604733) you need to PROXY the submission e.g.

Web Form -> Your PROXY Code -> Post to: http://www.pngbtob.com/webrater.php -> Your PROXY Code -> Browser
0
 

Author Comment

by:Smummery
Comment Utility
by proxy code do you mean the "get" method?
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
NO, the form needs to send the entered data, via a ANY method to YOUR OWN CODE (NOT www.pngbtob.com).
Your code will need to PROXY the data on (Send via a new POST request to http://www.pngbtob.com/webrater.php) and wait for a response from the site.
Once a response is received YOUR code should then interpret the response and generate / send something back to the browser.

May be of some use:

http://support.microsoft.com/kb/290591/en-us
http://www.captain.at/howto-ajax-form-post-request.php
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
Note: The proxy'ing will have to be done server side (ASP / VB), as an Ajax (Javascript) based solution will not be possible due to the www.pngbtob.com site not supporting / supplying a: Access-Control-Allow-* header, see: https://developer.mozilla.org/en/HTTP_access_control
0
 

Author Comment

by:Smummery
Comment Utility
Thank you. I have contacted our ISP to get that put on. Can you quickly tell why I keep getting the following errors in java script? I dont know much about it.

function makePOSTRequest(http://www.pngbtob.com/webrater.php) ,custdata value;="421",wid value;="4",wid2 value;="7176640500",origin value;="17545",dest value;="21014",class1 value;="100",weight1 value;="500") {
0
 
LVL 3

Expert Comment

by:moonlight
Comment Utility
you don't really need any ajax. just send the call to their server from within your serverside code, preferably using the same method as the html uses, retrieve the answer (still your server side code) and present it to the user in any way you like.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Smummery
Comment Utility
OKay, I think ( not sure) that I am getting somewhere here. I posted the following code and it sends to the vendor website but I get this error code on last linefor the write code. when I rem out the line the page appears to do nothing but I can see it says done. Any ideas?

Imports System.Xml


Partial Class xmltest3
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xmldoc


        xmlDoc = CreateObject("MSXML2.DOMDocument")

        xmlDoc.async = False
        xmlDoc.setProperty("ServerHTTPRequest", True)
        xmldoc.load("http://pngbtob.com/webrater.php?action=cusdata&cusdata=421&wid=4&wid2=7176640500&origin=17545&dest=21014&class1=100&weight1=500")


        Write(xmldoc.selectSingleNode("//results/status").Attributes.GetNamedItem("value").Text)

    End Sub
End Class
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
The HTML page below uses AJAX (Client Side JavaScript) code to do what I believe you want, extract the "value" and "ID" from the response, you can do something very similar server side if you so choose.

Note:
a) It's been quickly cobbled together from your example form and the code in the example links I provided earlier, so could do with a tidy up.
b) The multiple "Submit" buttons cover a few options:

/webrater.php                                     - Will work if the form is hosted on www.pngbtob.com
http://www.pngbtob.com/webrater.php   - As above and will work on a 3rd party sites if the HOST send a Access-Control-Allow-*  Header
/proxy/webrater.php                            - Will work on a 3rd party site if you implement / enable a Reverse Proxy tunnel to www.pngbtob.com
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="xmltest.aspx.vb" Inherits="xmltest" AspCompat="true"  %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<script type="text/javascript" language="javascript">

   var http_request = false;



function getXMLHttpRequest()

{ // See if the Browser supports Ajax

    if (window.XMLHttpRequest) {  // Mozilla, Safari, IE8+,...

        return new window.XMLHttpRequest;

    }

    else if (window.ActiveXObject) { // IE5->7

        try {

            return new ActiveXObject("MSXML2.XMLHTTP.6.0");

        }

        catch(ex) {}

        try {

            return new ActiveXObject("MSXML2.XMLHTTP.5.0");

        }

        catch(ex) {}

        try {

            return new ActiveXObject("MSXML2.XMLHTTP.4.0");

        }

        catch(ex) {}

        try {

            return new ActiveXObject("MSXML2.XMLHTTP.3.0");

        }

        catch(ex) {}

        try {

            return new ActiveXObject("MSXML2.XMLHTTP");

        }

        catch(ex) {}

        try {

            return new ActiveXObject("MSXML.XMLHTTP");

        }

        catch(ex) {}

        try {

            return new ActiveXObject("Microsoft.XMLHTTP");

        }

        catch(ex) {return null}

    }

}



   function makePOSTRequest(sURL, parameters) {

      http_request = getXMLHttpRequest();

      if (!http_request) {

         alert('Cannot create XMLHTTP instance');

         return false;

      }



      if (http_request.overrideMimeType) {

            // set type accordingly to anticipated content type

            //http_request.overrideMimeType('text/xml');

            http_request.overrideMimeType('text/html');

      }



      http_request.onreadystatechange = alertContents;

      http_request.open("POST", sURL, true);

      http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

      http_request.setRequestHeader("Content-length", parameters.length);

      http_request.setRequestHeader("Connection", "Keep-Alive");

      http_request.send(parameters);

   }



   function alertContents() {

      //Parse the returned Status and / or output



      if (http_request.readyState == 4) {

         if (http_request.status == 200) {



            var result = http_request.responseText;



            //See if we can create an XML parser to parse the returned XML

            if (window.DOMParser) {

              parser=new DOMParser();

              xmlDoc=parser.parseFromString( result,"text/xml");

            }

            else { // Internet Explorer

              xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

              xmlDoc.async="false";

              xmlDoc.loadXML(result);

            }



            var iID=0;

            var dVALUE=0;



            //If we have an XML parser pick out a few variables

            if (xmlDoc) {

              dVALUE = xmlDoc.getElementsByTagName('value').item(0).firstChild.nodeValue;

              iID    = xmlDoc.getElementsByTagName('id').item(0).firstChild.nodeValue;

            }



            //Display what we have back to the user

            document.getElementById('myspan').innerHTML = "ID="+ iID + "\n<BR>\nValue=" +dVALUE + "\n<BR>\n<HR>\n"+ result + "\n<BR>\n<HR>\n";

         } else {

            alert('There was a problem with the request:'+http_request.status+":"+http_request.readyState);

         }

      }

   }



   function get(obj, sURL) {

      var poststr = "custdata=" + encodeURI( document.myform.custdata.value ) +

                    "&wid="     + encodeURI( document.myform.wid.value ) +

                    "&wid2="    + encodeURI( document.myform.wid2.value ) +

                    "&origin="  + encodeURI( document.myform.origin.value ) +

                    "&dest="    + encodeURI( document.myform.dest.value ) +

                    "&class1="  + encodeURI( document.myform.class1.value ) +

                    "&weight1=" + encodeURI( document.myform.weight1.value )  +

                    "&btnSubmit=ANY+VALUE";

      makePOSTRequest(sURL, poststr);

   }

</script>





<br><br>

Entry-Form:<br>

<hr>

<!-- form action=http://www.pngbtob.com/webrater.php method=post -->

<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">



<input type=hidden name=custdata value="421">

<input type=hidden name=wid value=4>

<input type=hidden name=wid2 value=7176640500>



<table>

<tr>

        <td>Origin Zip</td>

        <td>

        <input type=text name=origin value=>

        </td>

</tr>

<tr>

        <td>Destination Zip</td>

        <td>

        <input type=text name=dest value=>

        </td>

</tr>

<tr>

        <td>Class Product 1</td>

        <td>

        <input type=text name=class1 value=>

        </td>

</tr>

<tr>

        <td>Weight Product 1</td>

        <td>

        <input type=text name=weight1 value=>

        </td>

</tr>



<tr>

        <td colspan=2>

        <input type="button" name="btnSubmit" value="Submit local" onclick="javascript:get(this.parentNode, '/webrater.php');">

        <input type="button" name="btnSubmit2" value="Submit remote" onclick="javascript:get(this.parentNode, 'http://www.pngbtob.com/webrater.php');">

        <input type="button" name="btnSubmit3" value="Submit proxy" onclick="javascript:get(this.parentNode, '/proxy/webrater.php');">

        <input type="submit" name="btnSubmit" value="Normal Submit Button">

        </td>

</tr>



</table>

    </form>





<br><br>

Server-Response:<br>

<hr>

<span name="myspan" id="myspan"></span>

<hr>



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    </form>

</body>

</html>

Open in new window

0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
0
 

Author Comment

by:Smummery
Comment Utility
I assume that your version did not include the URL, so I added it, but am having problems with the syntax again.,.I DO appreciate all your help with this! Can you check this and let me know or show me what to tweak?


<script type="text/javascript" language="javascript">
   var http_request = false;

function getXMLHttpRequest()
{ // See if the Browser supports Ajax
    if (window.XMLHttpRequest) {  // Mozilla, Safari, IE8+,...
        return new window.XMLHttpRequest;
    }
    else if (window.ActiveXObject) { // IE5->7
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.6.0");
        }
        catch(ex) {}
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.5.0");
        }
        catch(ex) {}
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.4.0");
        }
        catch(ex) {}
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(ex) {}
        try {
            return new ActiveXObject("MSXML2.XMLHTTP");
        }
        catch(ex) {}
        try {
            return new ActiveXObject("MSXML.XMLHTTP");
        }
        catch(ex) {}
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(ex) {return null}
    }
}

   function makePOSTRequest('http://pngbtob.com/webrater.php?action=cusdata&cusdata=421&wid=4&wid2=7176640500&origin=17545&dest=21014&class1=100&weight1=500) {
      http_request = getXMLHttpRequest();
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
      }

      http_request.onreadystatechange = alertContents;
      http_request.open("POST", sURL, true);
      http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "Keep-Alive");
      http_request.send(parameters);
   }

   function alertContents() {
      //Parse the returned Status and / or output

      if (http_request.readyState == 4) {
         if (http_request.status == 200) {

            var result = http_request.responseText;

            //See if we can create an XML parser to parse the returned XML
            if (window.DOMParser) {
              parser=new DOMParser();
              xmlDoc=parser.parseFromString( result,"text/xml");
            }
            else { // Internet Explorer
              xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
              xmlDoc.async="false";
              xmlDoc.loadXML(result);
            }

            var iID=0;
            var dVALUE=0;

            //If we have an XML parser pick out a few variables
            if (xmlDoc) {
              dVALUE = xmlDoc.getElementsByTagName('value').item(0).firstChild.nodeValue;
              iID    = xmlDoc.getElementsByTagName('id').item(0).firstChild.nodeValue;
            }

            //Display what we have back to the user
            document.getElementById('myspan').innerHTML = "ID="+ iID + "\n<BR>\nValue=" +dVALUE + "\n<BR>\n<HR>\n"+ result + "\n<BR>\n<HR>\n";
         } else {
            alert('There was a problem with the request:'+http_request.status+":"+http_request.readyState);
         }
      }
   }

   function get(obj, sURL) {
      var poststr = "custdata=" + encodeURI( document.myform.custdata.value ) +
                    "&wid="     + encodeURI( document.myform.wid.value ) +
                    "&wid2="    + encodeURI( document.myform.wid2.value ) +
                    "&origin="  + encodeURI( document.myform.origin.value ) +
                    "&dest="    + encodeURI( document.myform.dest.value ) +
                    "&class1="  + encodeURI( document.myform.class1.value ) +
                    "&weight1=" + encodeURI( document.myform.weight1.value )  +
                    "&btnSubmit=ANY+VALUE";
      makePOSTRequest(sURL, poststr);
   }
</script>


<br><br>
Entry-Form:<br>
<hr>
<!-- form action=http://www.pngbtob.com/webrater.php method=post -->
<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">

<input type=hidden name=custdata value="421">
<input type=hidden name=wid value=4>
<input type=hidden name=wid2 value=7176640500>

<table>
<tr>
        <td>Origin Zip</td>
        <td>
        <input type=text name=origin value=>
        </td>
</tr>
<tr>
        <td>Destination Zip</td>
        <td>
        <input type=text name=dest value=>
        </td>
</tr>
<tr>
        <td>Class Product 1</td>
        <td>
        <input type=text name=class1 value=>
        </td>
</tr>
<tr>
        <td>Weight Product 1</td>
        <td>
        <input type=text name=weight1 value=>
        </td>
</tr>

<tr>
        <td colspan=2>
        <input type="button" name="btnSubmit" value="Submit local" onclick="javascript:get(this.parentNode, 'http://pngbtob.com/webrater.php?action=cusdata&cusdata=421&wid=4&wid2=7176640500&origin=17545&dest=21014&class1=100&weight1=500);">
        <input type="button" name="btnSubmit2" value="Submit remote" onclick="javascript:get(this.parentNode, 'http://pngbtob.com/webrater.php?action=cusdata&cusdata=421&wid=4&wid2=7176640500&origin=17545&dest=21014&class1=100&weight1=500"');">
        <input type="button" name="btnSubmit3" value="Submit proxy" onclick="javascript:get(this.parentNode, '/proxy/webrater.php');">
        <input type="submit" name="btnSubmit" value="Normal Submit Button">
        </td>
</tr>

</table>
    </form>


<br><br>
Server-Response:<br>
<hr>
<span name="myspan" id="myspan"></span>
<hr>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
Toggle HighlightingOpen in New Window
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
My code will work as is, so for a start revert your changes to:

function makePOSTRequest(sURL, parameters) {

As the URL is passed by the Buttons, on the from.

Also revert the button logic changes, as the Patamerters are POST'ed by as part of the From submission, do not need to be manually attached as if you were going to send a GET request to the site.


Ajax-form1.jpg
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
Once you've reverted the changes, what's you problem?

Which of the submission methods have you tried?

What domain are you posting from (What domain is the form being served from)?

0
 

Author Comment

by:Smummery
Comment Utility
This is the form I am sending...and copied it exactly as your first suggestion. I am using it from an aspx page...would that make a difference?

Can you past your code that is working for me?


xmltest4.doc
0
 

Author Comment

by:Smummery
Comment Utility
Also, I am sending from my domain which is authenticated users, but I dont think this should be an issue because i could see the other returned page?

0
 

Author Comment

by:Smummery
Comment Utility
This is code I used and getting done with errors on page. I wonder if it is the authentication issue.? B

Would I be able to make some code that would send the username & Password the return?

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="xmltest4.aspx.vb" Inherits="xmltest4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script type="text/javascript" language="javascript">
    var http_request = false;

    function getXMLHttpRequest() { // See if the Browser supports Ajax
        if (window.XMLHttpRequest) {  // Mozilla, Safari, IE8+,...
            return new window.XMLHttpRequest;
        }
        else if (window.ActiveXObject) { // IE5->7
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.6.0");
            }
            catch (ex) { }
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.5.0");
            }
            catch (ex) { }
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.4.0");
            }
            catch (ex) { }
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex) { }
            try {
                return new ActiveXObject("MSXML2.XMLHTTP");
            }
            catch (ex) { }
            try {
                return new ActiveXObject("MSXML.XMLHTTP");
            }
            catch (ex) { }
            try {
                return new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (ex) { return null }
        }
    }

    function makePOSTRequest(sURL, parameters) {
        http_request = getXMLHttpRequest();
        if (!http_request) {
            alert('Cannot create XMLHTTP instance');
            return false;
        }

        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
        }

        http_request.onreadystatechange = alertContents;
        http_request.open("POST", sURL, true);
        http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        http_request.setRequestHeader("Content-length", parameters.length);
        http_request.setRequestHeader("Connection", "Keep-Alive");
        http_request.send(parameters);
    }

    function alertContents() {
        //Parse the returned Status and / or output

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {

                var result = http_request.responseText;

                //See if we can create an XML parser to parse the returned XML
                if (window.DOMParser) {
                    parser = new DOMParser();
                    xmlDoc = parser.parseFromString(result, "text/xml");
                }
                else { // Internet Explorer
                    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async = "false";
                    xmlDoc.loadXML(result);
                }

                var iID = 0;
                var dVALUE = 0;

                //If we have an XML parser pick out a few variables
                if (xmlDoc) {
                    dVALUE = xmlDoc.getElementsByTagName('value').item(0).firstChild.nodeValue;
                    iID = xmlDoc.getElementsByTagName('id').item(0).firstChild.nodeValue;
                }

                //Display what we have back to the user
                document.getElementById('myspan').innerHTML = "ID=" + iID + "\n<BR>\nValue=" + dVALUE + "\n<BR>\n<HR>\n" + result + "\n<BR>\n<HR>\n";
            } else {
                alert('There was a problem with the request:' + http_request.status + ":" + http_request.readyState);
            }
        }
    }

    functionget(obj, sURL) {
        var poststr = "custdata=" + encodeURI(document.myform.custdata.value) +
                    "&wid=" + encodeURI(document.myform.wid.value) +
                    "&wid2=" + encodeURI(document.myform.wid2.value) +
                    "&origin=" + encodeURI(document.myform.origin.value) +
                    "&dest=" + encodeURI(document.myform.dest.value) +
                    "&class1=" + encodeURI(document.myform.class1.value) +
                    "&weight1=" + encodeURI(document.myform.weight1.value) +
                    "&btnSubmit=ANY+VALUE";
        makePOSTRequest(sURL, poststr);
    }
</script>


<br><br>
Entry-Form:<br>
<hr>

<!-- form action=http://www.pngbtob.com/webrater.php method=post -->
<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">

<input type=hidden name=custdata value="421">
<input type=hidden name=wid value=4>
<input type=hidden name=wid2 value=7176640500>

<table>
<tr>
        <td>Origin Zip</td>
        <td>
        <input type=text name=origin value=>
        </td>
</tr>
<tr>
        <td>Destination Zip</td>
        <td>
        <input type=text name=dest value=>
        </td>
</tr>
<tr>
        <td>Class Product 1</td>
        <td>
        <input type=text name=class1 value=>
        </td>
</tr>
<tr>
        <td>Weight Product 1</td>
        <td>
        <input type=text name=weight1 value=>
        </td>
</tr>

<tr>
        <td colspan=2>
        <input type="button" name="btnSubmit" value="Submit local" onclick="javascript:get(this.parentNode, '/webrater.php');">
        <input type="button" name="btnSubmit2" value="Submit remote" onclick="javascript:get(this.parentNode, 'http://www.pngbtob.com/webrater.php');">
        <input type="button" name="btnSubmit3" value="Submit proxy" onclick="javascript:get(this.parentNode, '/proxy/webrater.php');">
        <input type="submit" name="btnSubmit" value="Normal Submit Button">
        </td>
</tr>

</table>
    </form>


<br><br>
Server-Response:<br>
<hr>
<span name="myspan" id="myspan"></span>
<hr>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
Toggle HighlightingOpen in New WindowSelect AllAccept Multiple Solutions Accept as Solution
0
 
LVL 3

Expert Comment

by:moonlight
Comment Utility
Hmm, actually I liked your first code, much cleaner :) imho you can add ajax stuff later when you know it works.

If you have got xmldoc.load working, do a xmldoc.save on your server, see that you actually got the answer.

selectsinglenode stuff usually don't work right away, null pointer exceptions are common, just split it into several lines, go step by step, I think you are on right track, good luck =)
0
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
Comment Utility
The HTML page I attached in POST [33608964] works as is, and is self contained (No additional code is necessary), as you can see by screen shot in POST [33613221]. The form will successfully POST values to: www.pngbtob.com, or a local page, via one of several means, parse the returned XML and display the value from a couple of the elements back in page.

I've attached another Pic, this time of the response XML, shown in Firebug, from both a Reverse Proxy call to the Real site, and to a dummy local "webrater.php" file I created to test the XML parsing, also attached.

If you want to use the test file and your host doesn't support php, spend a few seconds to creating an ASP version of the dummy php page, primarily:
a) loose the php at the top, after the <%
b) change the:   "header('Content-type: text/html');"     to:  Response.ContentType="text/html
c) Replace the echo's with response.write()
d) and the $_POST[ ]  with request.form()
e) Save you new ASP file, alter the "Submit local" button URL to use the new name. and give it a go.

As to why your having problems, unless you provide some more details of exactly what error your receiving (Code AND / OR Error Message) and what you were doing at the time I can't help.

Oh it appears you've suffered a Cun'n'Paste failure, as your code block / Word Document has as it's last line the Expert Exchange button text i.e.

"Toggle HighlightingOpen in New WindowSelect AllAccept Multiple Solutions Accept as Solution"

The lines presence won't do any harm, but shouldn't be there.

Oh, if you have it use Firefox and the "Live HTTP Headers"  and / or Firebug plug-in's to see what's going on, there are a selection of "How to use Firebug" videos kicking around on u-Tube and many Tutorials out-there.

<?php
header('Content-type: text/html');

echo "<?xml version='1.0'?>\n";
echo "<PNGB2B>\n";
echo " <rate>\n";
echo "   <id>574078</id>\n";
echo "   <origin>";
echo $_POST["origin"];
echo "</origin>\n";
echo "   <dest>";
echo $_POST["dest"];
echo "</dest>\n";
echo "   <value>162.14</value>\n";
echo "   <error></error>\n";
echo "   <custdata>";
echo $_POST['custdata'];
echo "</custdata>\n";
echo " </rate>\n";
echo "</PNGB2B>\n";
?>

Open in new window

Ajax-form2.jpg
0
 

Author Comment

by:Smummery
Comment Utility
Good Morning,

I re-posted the code (33608964) and uploaded it to my server...

http://www.humidifynow.com/xmltest.aspx

I then get an error 404;4 when i hit any of the four submit buttons.
0
 

Author Comment

by:Smummery
Comment Utility
Ok i uploaded the page, logged into my site, typed in the new url..and got the page.

I entered the variables and then when I use the submit remote button , the botom left corner of the page gives me small "error on page". When i move the mouse away it says done...but no return is shown.

I dont understand how this can work on yours and not on mine. I wonder if you could send back the copy and paste of the one that works for you...in case maybe i got something wrong?

Is this line supposed to be in green? I wonder if that is the problem?

<!-- form action=http://www.pngbtob.com/webrater.php method=post -->


0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
1) Have you created a local webrater.php  (local = placed the file on your own HOST)?   If not the "Submit Local" button will not work.

2) Have you set-up a local Reverse Proxy tunnel to www.pngbtob.com, configured under path "/proxy/", per the link I provided in post [33611043] ?  If not the "Submit proxy" button will not work.

3) Have you had the following Apache header options added to the www.pngbtob.com Virtual host defenition:
# Allow remote Client side AJAX Calls to this site
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "*"
Header set  Access-Control-Allow-Headers "*"
as you indicated you were going to do in post [33607729]? If not the "Submit Remote" option will not work.

The "Normal Submit Button" (form action) in the version of the code above is missing it's URL parameter, so will give a 404.

Please answer all of the above, when you have answered all 3 questions I'll reply.
0
 
LVL 26

Expert Comment

by:arober11
Comment Utility
0
 

Author Comment

by:Smummery
Comment Utility
we have found a much easier way using VB source code and some java.
0
 
LVL 3

Expert Comment

by:moonlight
Comment Utility
since we have fully answered your original question, you should accept answer now.
0
 

Author Comment

by:Smummery
Comment Utility
ok
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
Comment Utility
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now