2

I have a form that currently posts to one location, however i wish to send the data to another location at the same time but alter the Ids for example currently the name attribute for the email is id="ApplicationAppEmail" but i wish for on the second form submit the name attribute to be id="Email" as the second server accepts the post differently.

I have read numerous threads here and cannot find a exact way of doing this.

user1838222
  • 113
  • 1
  • 8
  • i think you mean the name attribute not the id attribute – antpaw Jul 22 '15 at 09:22
  • Similar question: How to send Post request with php: http://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php – Liren Jul 22 '15 at 09:25

4 Answers4

1

There is two thing you could do. When you POST through ajax you could:

<script>
       var getEmail;
$('#form').on('submit', function(){
    getEmail = $("#emailId").val();
    $.ajax({
        type: 'POST',
        url: 'https://test.com//Action/SavePageOne',
        crossDomain: true,
        data: { ApplicationAppEmail : getEmail  },
        success: function(responseData, textStatus, jqXHR) {
            var value = responseData.someKey;
        },
        error: function (responseData, textStatus, errorThrown) {
            alert('POST failed.');
        }
    }).then(function(){
     $.ajax({
        type: 'POST',
        url: 'https://test.com//Action/SavePageOne',
        crossDomain: true,
        data: { email: getEmail  },
        success: function(responseData, textStatus, jqXHR) {
            var value = responseData.someKey;
        },
        error: function (responseData, textStatus, errorThrown) {
            alert('POST failed.');
        }
    })
  })

  return false
})
</script>

Or on you backed of SavePageOne or SavePageTwo you could get the #emailId and cast it there.

Darren Willows
  • 2,053
  • 14
  • 21
0

When your from submit to original form action attribute, on that php page use ajax and manipulate relevant fields and action location. Please send both location, 1st and the other where your want to manipulate.

Tousif Ali
  • 1,214
  • 2
  • 11
  • 15
0

Yeah it's possible to do that. Send the form data to multiple files using jquery ajax or Native ajax methods.

 $.ajax({});

Send your form data to the first form using ajax and on completion of the first ajax request , do the native form submit .

But you can't send form data to two files using native form method.Only one file is allowed in it

Jijo John
  • 1,375
  • 9
  • 21
0

when you send the post request, it means get a response from server. just one response. if you want to send two requests, try $.ajax({})

example:

$('#form').on('submit', function(){
  $.ajax({
    url: 'api1',
    data: {}
  }).then(function(){
    $.ajax({
      url: 'api2',
      data: {}
    })
  })
  
  return false
})
Rein
  • 1
  • 1