attaching form contents to an url ajax











up vote
-1
down vote

favorite
1












im trying to add what the user entered into the form on to the end of a url using a ajax post, which the php form will submit to a web service, so far i can't figure this out any help would be appreciated



the ajax serializes the form and checks which radio button has been selected with this line var url = $("input[name='operation']:checked").val(); i want to add the parameters onto this url



this is the form code



  <form name="myform"   id="myform" method="POST">
<input type="radio" name="operation" value="currPost.php" id="Post"
onclick='displayFunctionPost("Post")'> Post
<input type="radio" name="operation" value="currPut.php" id="Put"
onclick='displayFunctionPut("Put")'> Put
<input type="radio" name="operation" value="currDel.php" id="Delete"
onclick='displayFunctionDelete("Del")'> Delete
<br>
Currency Code:
<br>

<input type="text" name="currencycode" id="currencycode" placeholder="Code" disabled>
<!--currency form-->
<br>
Currency Name
<br>
<input type="text" name= "currencyname" id="currencyname" placeholder="name" disabled>
<br>
<!---rates form--->
Rate(£=1):
<br>
<input type="number" name="rate" id="rate" placeholder="rate" disabled>
<!---countries form-->
<br>
Countries (comma separated if 1+)
<br>
<input type="text" name= "countries" id="countries" placeholder="countries"
disabled>
<br>

<!---xml response--->
<br>
Response Message:
<br>
<textarea id="xml_text" cols="70" rows="5"></textarea>

<input type="submit" name="submit" id="submit" value="submit" >

</form>


ajax



     <script>
$(document).ready(function(){
$("#myform").submit(function(e){
e.preventDefault();
var formData = $("#myform").serialize();

var url = $("input[name='operation']:checked").val();

// var url = $("#post_checked").attr("url");
$.ajax({
type: 'POST',
url: url,
data: formData,
dataType: 'text',
success: function(response){
console.log("Test hello world");
$('#xml_text').text(response);
}
});
});

});




this is the console output



 jquery.min.js:5 XHR finished loading: POST "http://isa.cems.uwe.ac.uk/~t7-mills/web/currPut.php".


but i want it to look like



jquery.min.js:5 XHR finished loading: POST "http://isa.cems.uwe.ac.uk/~t7-mills/web/currPut.php?currencycode=test&currencyname=test&rate=23&countries=test".


the php file



<?php


@date_default_timezone_set("GMT");
$xml= new DomDocument("1.0","UTF-8");
$xml->formatOutput=true;
$xml->preserveWhiteSpace=false;
$xml->load('rates.xml');

if(!$xml)
{
$currencies=$xml->createElement("currencies");
$xml->appendChild($currencies);
}
else
{
$currencies=$xml->firstChild;
}

if (isset($_GET['submit']))
{
$curcode = $_GET['currencycode'];
$newrate = $_GET['rate'];
$cname = $_GET['currencyname'];
$countries = $_GET['countries'];


$curr=$xml->createElement("currency");
$currencies->appendChild($curr);


$currate=$xml->createElement("code",$curcode);
$curr->appendChild($currate);
$currate->setAttribute("rate",$newrate);


$name=$xml->createElement("cname",$cname);
$curr->appendChild($name);

$places=$xml->createElement("cntry",$countries);
$curr->appendChild($places);


$xml->save('rates.xml');


echo <<<__xml
<?xml version="1.0" encoding="UTF-8"?>
<currency>{$_SERVER['PHP_SELF']}</currency>


__xml;



 }
?>









share|improve this question
























  • Why can't you just read it server side in the submitted post formData? If you must add it as url query string you need the base url and a query param name also and we don't know source of either. Please provide a Minimal, Complete, and Verifiable example and expected url result
    – charlietfl
    Nov 15 at 18:29












  • sorry but how would i read it in server side?
    – Mrtcupz
    Nov 15 at 18:31










  • Assuming that input is in the same form it would be in the serialized data
    – charlietfl
    Nov 15 at 18:32












  • updated the post i hope it meets the standards
    – Mrtcupz
    Nov 15 at 18:42










  • Sounds like you want to make a GET not a POST which is what you set in type. Try removing type:'POST' as GET is default and $.ajax will build the url for you from data option and the base url set in url
    – charlietfl
    Nov 15 at 18:43

















up vote
-1
down vote

favorite
1












im trying to add what the user entered into the form on to the end of a url using a ajax post, which the php form will submit to a web service, so far i can't figure this out any help would be appreciated



the ajax serializes the form and checks which radio button has been selected with this line var url = $("input[name='operation']:checked").val(); i want to add the parameters onto this url



this is the form code



  <form name="myform"   id="myform" method="POST">
<input type="radio" name="operation" value="currPost.php" id="Post"
onclick='displayFunctionPost("Post")'> Post
<input type="radio" name="operation" value="currPut.php" id="Put"
onclick='displayFunctionPut("Put")'> Put
<input type="radio" name="operation" value="currDel.php" id="Delete"
onclick='displayFunctionDelete("Del")'> Delete
<br>
Currency Code:
<br>

<input type="text" name="currencycode" id="currencycode" placeholder="Code" disabled>
<!--currency form-->
<br>
Currency Name
<br>
<input type="text" name= "currencyname" id="currencyname" placeholder="name" disabled>
<br>
<!---rates form--->
Rate(£=1):
<br>
<input type="number" name="rate" id="rate" placeholder="rate" disabled>
<!---countries form-->
<br>
Countries (comma separated if 1+)
<br>
<input type="text" name= "countries" id="countries" placeholder="countries"
disabled>
<br>

<!---xml response--->
<br>
Response Message:
<br>
<textarea id="xml_text" cols="70" rows="5"></textarea>

<input type="submit" name="submit" id="submit" value="submit" >

</form>


ajax



     <script>
$(document).ready(function(){
$("#myform").submit(function(e){
e.preventDefault();
var formData = $("#myform").serialize();

var url = $("input[name='operation']:checked").val();

// var url = $("#post_checked").attr("url");
$.ajax({
type: 'POST',
url: url,
data: formData,
dataType: 'text',
success: function(response){
console.log("Test hello world");
$('#xml_text').text(response);
}
});
});

});




this is the console output



 jquery.min.js:5 XHR finished loading: POST "http://isa.cems.uwe.ac.uk/~t7-mills/web/currPut.php".


but i want it to look like



jquery.min.js:5 XHR finished loading: POST "http://isa.cems.uwe.ac.uk/~t7-mills/web/currPut.php?currencycode=test&currencyname=test&rate=23&countries=test".


the php file



<?php


@date_default_timezone_set("GMT");
$xml= new DomDocument("1.0","UTF-8");
$xml->formatOutput=true;
$xml->preserveWhiteSpace=false;
$xml->load('rates.xml');

if(!$xml)
{
$currencies=$xml->createElement("currencies");
$xml->appendChild($currencies);
}
else
{
$currencies=$xml->firstChild;
}

if (isset($_GET['submit']))
{
$curcode = $_GET['currencycode'];
$newrate = $_GET['rate'];
$cname = $_GET['currencyname'];
$countries = $_GET['countries'];


$curr=$xml->createElement("currency");
$currencies->appendChild($curr);


$currate=$xml->createElement("code",$curcode);
$curr->appendChild($currate);
$currate->setAttribute("rate",$newrate);


$name=$xml->createElement("cname",$cname);
$curr->appendChild($name);

$places=$xml->createElement("cntry",$countries);
$curr->appendChild($places);


$xml->save('rates.xml');


echo <<<__xml
<?xml version="1.0" encoding="UTF-8"?>
<currency>{$_SERVER['PHP_SELF']}</currency>


__xml;



 }
?>









share|improve this question
























  • Why can't you just read it server side in the submitted post formData? If you must add it as url query string you need the base url and a query param name also and we don't know source of either. Please provide a Minimal, Complete, and Verifiable example and expected url result
    – charlietfl
    Nov 15 at 18:29












  • sorry but how would i read it in server side?
    – Mrtcupz
    Nov 15 at 18:31










  • Assuming that input is in the same form it would be in the serialized data
    – charlietfl
    Nov 15 at 18:32












  • updated the post i hope it meets the standards
    – Mrtcupz
    Nov 15 at 18:42










  • Sounds like you want to make a GET not a POST which is what you set in type. Try removing type:'POST' as GET is default and $.ajax will build the url for you from data option and the base url set in url
    – charlietfl
    Nov 15 at 18:43















up vote
-1
down vote

favorite
1









up vote
-1
down vote

favorite
1






1





im trying to add what the user entered into the form on to the end of a url using a ajax post, which the php form will submit to a web service, so far i can't figure this out any help would be appreciated



the ajax serializes the form and checks which radio button has been selected with this line var url = $("input[name='operation']:checked").val(); i want to add the parameters onto this url



this is the form code



  <form name="myform"   id="myform" method="POST">
<input type="radio" name="operation" value="currPost.php" id="Post"
onclick='displayFunctionPost("Post")'> Post
<input type="radio" name="operation" value="currPut.php" id="Put"
onclick='displayFunctionPut("Put")'> Put
<input type="radio" name="operation" value="currDel.php" id="Delete"
onclick='displayFunctionDelete("Del")'> Delete
<br>
Currency Code:
<br>

<input type="text" name="currencycode" id="currencycode" placeholder="Code" disabled>
<!--currency form-->
<br>
Currency Name
<br>
<input type="text" name= "currencyname" id="currencyname" placeholder="name" disabled>
<br>
<!---rates form--->
Rate(£=1):
<br>
<input type="number" name="rate" id="rate" placeholder="rate" disabled>
<!---countries form-->
<br>
Countries (comma separated if 1+)
<br>
<input type="text" name= "countries" id="countries" placeholder="countries"
disabled>
<br>

<!---xml response--->
<br>
Response Message:
<br>
<textarea id="xml_text" cols="70" rows="5"></textarea>

<input type="submit" name="submit" id="submit" value="submit" >

</form>


ajax



     <script>
$(document).ready(function(){
$("#myform").submit(function(e){
e.preventDefault();
var formData = $("#myform").serialize();

var url = $("input[name='operation']:checked").val();

// var url = $("#post_checked").attr("url");
$.ajax({
type: 'POST',
url: url,
data: formData,
dataType: 'text',
success: function(response){
console.log("Test hello world");
$('#xml_text').text(response);
}
});
});

});




this is the console output



 jquery.min.js:5 XHR finished loading: POST "http://isa.cems.uwe.ac.uk/~t7-mills/web/currPut.php".


but i want it to look like



jquery.min.js:5 XHR finished loading: POST "http://isa.cems.uwe.ac.uk/~t7-mills/web/currPut.php?currencycode=test&currencyname=test&rate=23&countries=test".


the php file



<?php


@date_default_timezone_set("GMT");
$xml= new DomDocument("1.0","UTF-8");
$xml->formatOutput=true;
$xml->preserveWhiteSpace=false;
$xml->load('rates.xml');

if(!$xml)
{
$currencies=$xml->createElement("currencies");
$xml->appendChild($currencies);
}
else
{
$currencies=$xml->firstChild;
}

if (isset($_GET['submit']))
{
$curcode = $_GET['currencycode'];
$newrate = $_GET['rate'];
$cname = $_GET['currencyname'];
$countries = $_GET['countries'];


$curr=$xml->createElement("currency");
$currencies->appendChild($curr);


$currate=$xml->createElement("code",$curcode);
$curr->appendChild($currate);
$currate->setAttribute("rate",$newrate);


$name=$xml->createElement("cname",$cname);
$curr->appendChild($name);

$places=$xml->createElement("cntry",$countries);
$curr->appendChild($places);


$xml->save('rates.xml');


echo <<<__xml
<?xml version="1.0" encoding="UTF-8"?>
<currency>{$_SERVER['PHP_SELF']}</currency>


__xml;



 }
?>









share|improve this question















im trying to add what the user entered into the form on to the end of a url using a ajax post, which the php form will submit to a web service, so far i can't figure this out any help would be appreciated



the ajax serializes the form and checks which radio button has been selected with this line var url = $("input[name='operation']:checked").val(); i want to add the parameters onto this url



this is the form code



  <form name="myform"   id="myform" method="POST">
<input type="radio" name="operation" value="currPost.php" id="Post"
onclick='displayFunctionPost("Post")'> Post
<input type="radio" name="operation" value="currPut.php" id="Put"
onclick='displayFunctionPut("Put")'> Put
<input type="radio" name="operation" value="currDel.php" id="Delete"
onclick='displayFunctionDelete("Del")'> Delete
<br>
Currency Code:
<br>

<input type="text" name="currencycode" id="currencycode" placeholder="Code" disabled>
<!--currency form-->
<br>
Currency Name
<br>
<input type="text" name= "currencyname" id="currencyname" placeholder="name" disabled>
<br>
<!---rates form--->
Rate(£=1):
<br>
<input type="number" name="rate" id="rate" placeholder="rate" disabled>
<!---countries form-->
<br>
Countries (comma separated if 1+)
<br>
<input type="text" name= "countries" id="countries" placeholder="countries"
disabled>
<br>

<!---xml response--->
<br>
Response Message:
<br>
<textarea id="xml_text" cols="70" rows="5"></textarea>

<input type="submit" name="submit" id="submit" value="submit" >

</form>


ajax



     <script>
$(document).ready(function(){
$("#myform").submit(function(e){
e.preventDefault();
var formData = $("#myform").serialize();

var url = $("input[name='operation']:checked").val();

// var url = $("#post_checked").attr("url");
$.ajax({
type: 'POST',
url: url,
data: formData,
dataType: 'text',
success: function(response){
console.log("Test hello world");
$('#xml_text').text(response);
}
});
});

});




this is the console output



 jquery.min.js:5 XHR finished loading: POST "http://isa.cems.uwe.ac.uk/~t7-mills/web/currPut.php".


but i want it to look like



jquery.min.js:5 XHR finished loading: POST "http://isa.cems.uwe.ac.uk/~t7-mills/web/currPut.php?currencycode=test&currencyname=test&rate=23&countries=test".


the php file



<?php


@date_default_timezone_set("GMT");
$xml= new DomDocument("1.0","UTF-8");
$xml->formatOutput=true;
$xml->preserveWhiteSpace=false;
$xml->load('rates.xml');

if(!$xml)
{
$currencies=$xml->createElement("currencies");
$xml->appendChild($currencies);
}
else
{
$currencies=$xml->firstChild;
}

if (isset($_GET['submit']))
{
$curcode = $_GET['currencycode'];
$newrate = $_GET['rate'];
$cname = $_GET['currencyname'];
$countries = $_GET['countries'];


$curr=$xml->createElement("currency");
$currencies->appendChild($curr);


$currate=$xml->createElement("code",$curcode);
$curr->appendChild($currate);
$currate->setAttribute("rate",$newrate);


$name=$xml->createElement("cname",$cname);
$curr->appendChild($name);

$places=$xml->createElement("cntry",$countries);
$curr->appendChild($places);


$xml->save('rates.xml');


echo <<<__xml
<?xml version="1.0" encoding="UTF-8"?>
<currency>{$_SERVER['PHP_SELF']}</currency>


__xml;



 }
?>






php jquery html ajax post






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 18:50

























asked Nov 15 at 18:26









Mrtcupz

64




64












  • Why can't you just read it server side in the submitted post formData? If you must add it as url query string you need the base url and a query param name also and we don't know source of either. Please provide a Minimal, Complete, and Verifiable example and expected url result
    – charlietfl
    Nov 15 at 18:29












  • sorry but how would i read it in server side?
    – Mrtcupz
    Nov 15 at 18:31










  • Assuming that input is in the same form it would be in the serialized data
    – charlietfl
    Nov 15 at 18:32












  • updated the post i hope it meets the standards
    – Mrtcupz
    Nov 15 at 18:42










  • Sounds like you want to make a GET not a POST which is what you set in type. Try removing type:'POST' as GET is default and $.ajax will build the url for you from data option and the base url set in url
    – charlietfl
    Nov 15 at 18:43




















  • Why can't you just read it server side in the submitted post formData? If you must add it as url query string you need the base url and a query param name also and we don't know source of either. Please provide a Minimal, Complete, and Verifiable example and expected url result
    – charlietfl
    Nov 15 at 18:29












  • sorry but how would i read it in server side?
    – Mrtcupz
    Nov 15 at 18:31










  • Assuming that input is in the same form it would be in the serialized data
    – charlietfl
    Nov 15 at 18:32












  • updated the post i hope it meets the standards
    – Mrtcupz
    Nov 15 at 18:42










  • Sounds like you want to make a GET not a POST which is what you set in type. Try removing type:'POST' as GET is default and $.ajax will build the url for you from data option and the base url set in url
    – charlietfl
    Nov 15 at 18:43


















Why can't you just read it server side in the submitted post formData? If you must add it as url query string you need the base url and a query param name also and we don't know source of either. Please provide a Minimal, Complete, and Verifiable example and expected url result
– charlietfl
Nov 15 at 18:29






Why can't you just read it server side in the submitted post formData? If you must add it as url query string you need the base url and a query param name also and we don't know source of either. Please provide a Minimal, Complete, and Verifiable example and expected url result
– charlietfl
Nov 15 at 18:29














sorry but how would i read it in server side?
– Mrtcupz
Nov 15 at 18:31




sorry but how would i read it in server side?
– Mrtcupz
Nov 15 at 18:31












Assuming that input is in the same form it would be in the serialized data
– charlietfl
Nov 15 at 18:32






Assuming that input is in the same form it would be in the serialized data
– charlietfl
Nov 15 at 18:32














updated the post i hope it meets the standards
– Mrtcupz
Nov 15 at 18:42




updated the post i hope it meets the standards
– Mrtcupz
Nov 15 at 18:42












Sounds like you want to make a GET not a POST which is what you set in type. Try removing type:'POST' as GET is default and $.ajax will build the url for you from data option and the base url set in url
– charlietfl
Nov 15 at 18:43






Sounds like you want to make a GET not a POST which is what you set in type. Try removing type:'POST' as GET is default and $.ajax will build the url for you from data option and the base url set in url
– charlietfl
Nov 15 at 18:43



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325750%2fattaching-form-contents-to-an-url-ajax%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325750%2fattaching-form-contents-to-an-url-ajax%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?