Shakur Posted April 14, 2010 Share Posted April 14, 2010 Hello I'm trying to do something in AJAX but it seems not to be possible. On the Client side I have an html form with a button which when clicked calls a javascript function named sendMail(). This function then creates an AJAX request to a specified url. On the Server side I'm creating some table and then I return and display the table on the browser side. So far so good, now I was trying to embed inside the table (Server side) a simple Paypal button. The problem is when I click on the Button it does not redirect me to paypal but rather on my site root. I speculate that the problem is that I cannot have a form post on the server side of an AJAX request. Is this TRUE? If yes what alternatives do I have? I need to display the button on the server side. Here is how I call the AJAX on the client side: In HTML: <form action="index.php" method="post" name="adminForm" id="adminForm" > <input type="button" class="my_button" name="current" id="currrent2" value="Submit" onclick="sendMail();" /></form> In Javascript I have: function sendMail (){ var url2="http://www.someurl.com"; xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } xmlhttp.onreadystatechange=stateChanged2; xmlhttp.open("GET",url2,true); xmlhttp.send(null); } function stateChanged2() { if (xmlhttp.readyState==4) { document.getElementById("emailSent").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } And on Server side I display the button like this: <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> ... <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> Link to comment https://forums.phpfreaks.com/topic/198475-form-post-on-ajax-server-side/ Share on other sites More sharing options...
trq Posted April 14, 2010 Share Posted April 14, 2010 The problem is when I click on the Button it does not redirect me to paypal but rather on my site root. Yes, your ajax request makes a request to your server root. What exactly do you expect to happen? And on Server side I display the button like this: You can't display anything server side. Link to comment https://forums.phpfreaks.com/topic/198475-form-post-on-ajax-server-side/#findComment-1041564 Share on other sites More sharing options...
Shakur Posted April 14, 2010 Author Share Posted April 14, 2010 The problem is when I click on the Button it does not redirect me to paypal but rather on my site root. Yes, your ajax request makes a request to your server root. What exactly do you expect to happen? And on Server side I display the button like this: You can't display anything server side. Hello thorpe and thank you for your answer! I was talking about the Paypal button which certainly does not make a request to my site root! The button is displayed in the client side but I meant that I want it to be visible inside the code returned from the server side. Anyway thank you for your reply.. Any other ideas? Link to comment https://forums.phpfreaks.com/topic/198475-form-post-on-ajax-server-side/#findComment-1041573 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.