Jump to content

Form post on AJAX server side


Shakur

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.