开发者

Javascript - How do I capture and respond to a post?

I am developing an application to respond to a punch out, but am missing something. I can create the reponse XML document fine, but the receiving end is not seeing my response. I have found hundreds of examples on the web about the post process, but cannot seem to figure out what the server is supposed to do to reply to the post. If anyone can offer an example of the server side of this, that would be greatly appreciated.

Update

Here is the code that I have. I did replace the SEND with a display to see what it was I am trying to send. I am very new to this, so any insight would be helpful.

<script language="javascript">



var xmlhttp;
var xmlrtn;
<!-- Begin
  Stamp = new Date();
  year = Stamp.getYear();
  month = Stamp.getMonth() + 1;
  if (month < 10) {month = "0" + month;}
  ddate = Stamp.getDate();
  if (ddate < 10) {ddate = "0" + ddate;}
  if (year < 2000) year = 1900 + year;
  //document.write(year + "-" + month + "-" + ddate);
  timestamp = year + "-" + month + "-" + ddate;
  var Hours;
  var Mins;
  var Time;
  Hours = Stamp.getHours();
  Mins = Stamp.getMinutes();
  if (Mins < 10) {
   Mins = "0" + Mins;
  } 
  Secs = Stamp.getSeconds();
  if (Secs < 10) {Secs = "0" + Secs;}
  //document.write('T' + Hours + ":" + Mins + ":" + Secs);
  timestamp = timestamp + 'T' + Hours + ":" + Mins + ":" + Secs;
 // End -->

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

 var o="&lt;";
 var c="/" + "&gt;"; 
 var tc="&lt;" + "/";
 var e="&gt;"; 
 var params=new Array();
 var xmlrtn = '';



function loadXML(xmlFile)
 {
   xmlhttp.async="false";
   xmlhttp.onreadystatechange=verify;
   xmlhttp.load(xmlFile);
   xmlObj=xmlhttp.documentElement;
 }

function verify()
 {
   // 0 Object is not initialized
   // 1 Loading object is loading data
   // 2 Loaded object has loaded data
   // 3 Data from object can be worked with
   // 4 Object completely initialized
   if (xmlhttp.readyState != 4)
  {
        return false;
  }
 }


</script>
</head>
<body>



 <script language="javascript">


//Read in XML file
 loadXML('https://www.americantexche开发者_如何转开发m.com:9443/storefrontContent/attach/sample.xml');

 //Assign Variables
 var xmlver='?xml version="1.0"?';
 var doctype='!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.1.007/cXML.dtd"';

 xmlLang=xmlObj.getAttribute("xml:lang");

 var cxmltag=xmlObj.tagName;
 var cxmlval=' version="' + xmlObj.getAttribute("version") + '" payloadID="' + xmlObj.getAttribute("payloadID") + '"   timestamp="' + timestamp + '"';

 var resptag='Response';
 var statustag='Status code="200" text="success" ';
 var poutsrtag='PunchOutSetupResponse';
 var startpgtag='StartPage';
 var urltag='URL';
 var urlval='https://www.americantexchem.com:9443/storefrontCommerce/jsp/wynlogin.jsp';
 var srcurlval = xmlObj.childNodes(1).childNodes(0).childNodes(2).childNodes(0).firstChild.text; //URL content

 // post


  params[0] = o + xmlver + e;
  params[1] = o + doctype + e;
  params[2] = o + cxmltag;
  params[3] = cxmlval + e;
  params[4] = o + resptag + e;
  params[5] = o + statustag + c;
  params[6] = o + poutsrtag + e;
  params[7] = o + startpgtag + e;
  params[8] = o + urltag + e;
  params[9] = urlval;
  params[10] = tc + urltag + e;
  params[11] = tc + startpgtag + e;
  params[12] = tc + poutsrtag + e;
  params[13] = tc + resptag + e;
  params[14] = tc + cxmltag + e;

  for (var i in params) { 
           if (params.hasOwnProperty(i)) { 
           // var input = document.createElement('input'); 
               //   input.type = 'hidden'; 
                 // input.name = i; 
           //input.value = params[i]; 
              //    form.appendChild(input);
              xmlrtn = xmlrtn + params[i];  
    } 
   } 

 // alert (xmlObj.xml);
 document.write (xmlrtn);



 /*
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  fileBool = fso.FileExists("C:\\out.xml");
  if(fileBool)
  {
   //document.write("Test-fileBool");
   fso.DeleteFile("C:\\out.xml",true);
  }

  var fso, s; 
    fso = new ActiveXObject("Scripting.FileSystemObject"); 
    s = fso.OpenTextFile("C:\\out.xml" , 8, true); 


  s.writeline (o + xmlver + e);
  s.writeline (o + doctype + e);
  s.writeline (o + cxmltag);
  s.writeline (cxmlval + e);
  s.writeline (o + resptag + e);
  s.writeline (o + statustag + c);
  s.writeline (o + poutsrtag + e);
  s.writeline (o + startpgtag + e);
  s.writeline (o + urltag + e);
  s.writeline (urlval);
  s.writeline (tc + urltag + e);
  s.writeline (tc + startpgtag + e);
  s.writeline (tc + poutsrtag + e);
  s.writeline (tc + resptag + e);
  s.writeline (tc + cxmltag + e);

//  s.writeline (xmlObj.xml); // the whole source xml document

 s.Close(); 

*/
</script>
</body>
</html>


This will depend a bit on your server side technology. Here is an example post using asp.net mvc.

http://blog.bobcravens.com/2009/11/ajax-calls-to-asp-net-mvc-action-methods-using-jquery/

Hope this helps getting you started

Bob

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜