January 19, 201016 yr Hi, I am integrating a clients current shopping cart into the Barclaycard epdg store using PHP and XML and I have came across what (I hope) is a fairly simple XML query. When the customer is going through the checkout, I need to submit the customers details (name, address, card number etc) to the Barclays store via XML. I then need to parse the XML the site returns to confirm the trransaction has gone through. However, I need to do this without leaving my clients site. Basically then, how do I submit XML to a URL (in this case https://secure2.epdq.co.uk:11500/) without using an HTML form? If I use a form with the above URL as the action, the browser navigates to that page. I need to stay on the same page but be able to submit the XML and then parse the XML which is returned. All help is greatly appreciated. Thanks -John
January 19, 201016 yr @ShannonPrue There are many different ways you can work with xml based Web Services, one popular approach is to use the jQueryjavascript library. $.post("test.php"); Post the contents of a form named "testform" $.post("test.php", $("#testform").serialize()); Or here's a function that handles the call back (data returned from the service) $.post("test.php", { name: "John", time: "2pm" }, function(data){ alert("Data Loaded: " + data); }); If you prefer not to use an entire library, I have an example here that uses raw javascript to query a local service and handle the return. If you are not using RSSBus you can strip out the <rsb:*> tags and use just the javascript. changing xmlhttp.open('GET', '[[url]]?timespate='+ new Date().getTime(), true); to xmlhttp.open('POST', 'http://www.SERVICEYOUWANTTOPOSTTO.COM?timespate='+ new Date().getTime(), true);
January 20, 201016 yr Author Thanks for your reply mate. So, using your RSSBus example, could I activate the javascript with a form submit button by saying something like: <?php if(isset($_POST['submit'])) { //Javascript goes here } ?> If I can do this, which part of the javascript sample you have on RSSBus sends the XML, and how do I parse it when it returns? Thanks again.
January 21, 201016 yr The idea here is to have javascript submit the form for you, overriding the default form action, If your page reloads you break the communication with the api, so as stated earlier, the general idea is to have a user click a sumbit button, but instead of this button submitting a form in the traditional sense it instead invokes a javascript function, this javascript function will post the data in the form to the api (asynchronously) behind the scenes without reloading the page, this javascript function then sits there waiting for the return values from the api, when this happens you have javascript respond to the return and redirect as necessary. Here is an example of invoking javascript with a form submit button, but blocking the page from reloading. <script language="JavaScript"> function myFunction() { $.post("test.php", $("#myForm").serialize(), function(data){ alert("Data Loaded: " + data); }); return false; } </script> <form id="myForm" onsubmit="return myFunction();"> <input name="input1"> <input type="submit" value="Submit"> </form> Note: the above code will take inputs into the form, when a user clicks submit the function myFunction() is invoked, which in turn will serialize the form values and post them to test.php, wait for test.php to load and then alert you the data returned, in the section you see alert(data...) you will redirect as necessary here. This is extremely powerful way to build web pages as you now have complete control over the behavior of the page. note the above code uses the jQuery framework.
January 22, 201016 yr ..which is in short what I said in my post right before yours, except I used JQuery :) Yep I was just adding a bit more detail to the explanation.
January 22, 201016 yr You might want to take a look at using cURL. You can still use a html form with a method to submit to a php script which will send this XML data. I wouldn't recommend doing this with JavaScript as it will allow anyone to see where this data is being sent to, how and allow the possibility of mass requests to the server. There is also the possibility that the client doesn't have JavaScript enabled, so in that instance there won't be any submission
January 22, 201016 yr This worries me. Someone who doesn't know what they're doing jumping in at the deep end. I recommend you pay someone who knows what they're doing.. simply because you're handling credit cards!
Create an account or sign in to comment