Solved

Handling XML response after sending HTML Post to URL

Posted on 2010-09-04
39
1,482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 12
  • 6
  • +2
39 Comments
 
LVL 7

Expert Comment

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

Expert Comment

by:arober11
ID: 33604733
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
ID: 33604737
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 7

Expert Comment

by:wdfdo1986
ID: 33604742
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
ID: 33604746
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
ID: 33604773
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
ID: 33604789
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
ID: 33604805
Just check out the tutorials, they have the examples... :)
0
 

Author Comment

by:Smummery
ID: 33604822
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
ID: 33604842
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
ID: 33606701
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
ID: 33606940
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
ID: 33606949
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
ID: 33607235
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
ID: 33607455
by proxy code do you mean the "get" method?
0
 
LVL 26

Expert Comment

by:arober11
ID: 33607490
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
ID: 33607654
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
ID: 33607729
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
ID: 33607839
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
 

Author Comment

by:Smummery
ID: 33608140
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
ID: 33608964
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
ID: 33611043
0
 

Author Comment

by:Smummery
ID: 33612104
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
ID: 33613221
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
ID: 33613234
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
ID: 33613743
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
ID: 33613777
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
ID: 33613816
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
ID: 33613950
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
ID: 33614895
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
ID: 33617069
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
ID: 33617148
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
ID: 33617249
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
ID: 33627617
0
 

Author Comment

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

Expert Comment

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

Author Comment

by:Smummery
ID: 34041800
ok
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34078298
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

733 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