During an $.ajax call some data is lost












0














I have a form with a multiple select box. When I select more than one option and send the form via an ajax cal to a php file, only the last option will be saved.
Why is that so?



This is the AJAX call:



var daten = $('#formulargesamt').serialize();
console.log(daten);

$.ajax({
url: "/ajax/neukundenanlage/get_formular.php",
data: daten,
method: "POST",
});


In the console.log prompt all data is there (as a string). However in the PHP file it is an array with only the last selected option.



Does anyone have a ideas how I can fix this? Thanks



edit:



the html code:



<div class="container">
<form action="/ajax/neukundenanlage/get_formular.php" method="post"
name="formular" id="formulargesamt">


(...)



    <div class="alert fade in" role="alert" id="resultmsg"  
style="display:none;">
<button type="button" class="close" data-dismiss="alert" aria-
label="Close"><span aria-hidden="true">×</span></button> <span
id="resulttxt"></span>
</div>
</div>


the PHP code:



<?php
print_r($_POST);


the prompt from console.log:



ed_kid=107&medienverzeichnis=konradin&ed_kbid=&ma_id=0&job_id=0&absendername=&fromaddress=&replyto=&feedbackadresse=&login=agotzens%40mbmedien.de&login=bcioba%40mbmedien.de










share|improve this question
























  • The important parts we need to see here is the string generated from serialize() and your PHP.
    – Rory McCrossan
    Nov 20 at 10:02










  • How is your html? The name attribute should be something like: name="date" instead of only name="date"
    – Eva
    Nov 20 at 10:05












  • please provide your html code
    – Bhoomi patel
    Nov 20 at 10:07










  • HI folks, thanks for the replys. @Eva Why should I add an array-bracket to the name?
    – Peter
    Nov 20 at 12:16










  • If ever you have input fields with the same name, adding an "array-bracket" will store it in an array. Without it, serialize will use the last input value.
    – claw68
    Nov 20 at 12:48
















0














I have a form with a multiple select box. When I select more than one option and send the form via an ajax cal to a php file, only the last option will be saved.
Why is that so?



This is the AJAX call:



var daten = $('#formulargesamt').serialize();
console.log(daten);

$.ajax({
url: "/ajax/neukundenanlage/get_formular.php",
data: daten,
method: "POST",
});


In the console.log prompt all data is there (as a string). However in the PHP file it is an array with only the last selected option.



Does anyone have a ideas how I can fix this? Thanks



edit:



the html code:



<div class="container">
<form action="/ajax/neukundenanlage/get_formular.php" method="post"
name="formular" id="formulargesamt">


(...)



    <div class="alert fade in" role="alert" id="resultmsg"  
style="display:none;">
<button type="button" class="close" data-dismiss="alert" aria-
label="Close"><span aria-hidden="true">×</span></button> <span
id="resulttxt"></span>
</div>
</div>


the PHP code:



<?php
print_r($_POST);


the prompt from console.log:



ed_kid=107&medienverzeichnis=konradin&ed_kbid=&ma_id=0&job_id=0&absendername=&fromaddress=&replyto=&feedbackadresse=&login=agotzens%40mbmedien.de&login=bcioba%40mbmedien.de










share|improve this question
























  • The important parts we need to see here is the string generated from serialize() and your PHP.
    – Rory McCrossan
    Nov 20 at 10:02










  • How is your html? The name attribute should be something like: name="date" instead of only name="date"
    – Eva
    Nov 20 at 10:05












  • please provide your html code
    – Bhoomi patel
    Nov 20 at 10:07










  • HI folks, thanks for the replys. @Eva Why should I add an array-bracket to the name?
    – Peter
    Nov 20 at 12:16










  • If ever you have input fields with the same name, adding an "array-bracket" will store it in an array. Without it, serialize will use the last input value.
    – claw68
    Nov 20 at 12:48














0












0








0







I have a form with a multiple select box. When I select more than one option and send the form via an ajax cal to a php file, only the last option will be saved.
Why is that so?



This is the AJAX call:



var daten = $('#formulargesamt').serialize();
console.log(daten);

$.ajax({
url: "/ajax/neukundenanlage/get_formular.php",
data: daten,
method: "POST",
});


In the console.log prompt all data is there (as a string). However in the PHP file it is an array with only the last selected option.



Does anyone have a ideas how I can fix this? Thanks



edit:



the html code:



<div class="container">
<form action="/ajax/neukundenanlage/get_formular.php" method="post"
name="formular" id="formulargesamt">


(...)



    <div class="alert fade in" role="alert" id="resultmsg"  
style="display:none;">
<button type="button" class="close" data-dismiss="alert" aria-
label="Close"><span aria-hidden="true">×</span></button> <span
id="resulttxt"></span>
</div>
</div>


the PHP code:



<?php
print_r($_POST);


the prompt from console.log:



ed_kid=107&medienverzeichnis=konradin&ed_kbid=&ma_id=0&job_id=0&absendername=&fromaddress=&replyto=&feedbackadresse=&login=agotzens%40mbmedien.de&login=bcioba%40mbmedien.de










share|improve this question















I have a form with a multiple select box. When I select more than one option and send the form via an ajax cal to a php file, only the last option will be saved.
Why is that so?



This is the AJAX call:



var daten = $('#formulargesamt').serialize();
console.log(daten);

$.ajax({
url: "/ajax/neukundenanlage/get_formular.php",
data: daten,
method: "POST",
});


In the console.log prompt all data is there (as a string). However in the PHP file it is an array with only the last selected option.



Does anyone have a ideas how I can fix this? Thanks



edit:



the html code:



<div class="container">
<form action="/ajax/neukundenanlage/get_formular.php" method="post"
name="formular" id="formulargesamt">


(...)



    <div class="alert fade in" role="alert" id="resultmsg"  
style="display:none;">
<button type="button" class="close" data-dismiss="alert" aria-
label="Close"><span aria-hidden="true">×</span></button> <span
id="resulttxt"></span>
</div>
</div>


the PHP code:



<?php
print_r($_POST);


the prompt from console.log:



ed_kid=107&medienverzeichnis=konradin&ed_kbid=&ma_id=0&job_id=0&absendername=&fromaddress=&replyto=&feedbackadresse=&login=agotzens%40mbmedien.de&login=bcioba%40mbmedien.de







jquery html ajax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 12:39









jnuK

1,5161325




1,5161325










asked Nov 20 at 10:00









Peter

104




104












  • The important parts we need to see here is the string generated from serialize() and your PHP.
    – Rory McCrossan
    Nov 20 at 10:02










  • How is your html? The name attribute should be something like: name="date" instead of only name="date"
    – Eva
    Nov 20 at 10:05












  • please provide your html code
    – Bhoomi patel
    Nov 20 at 10:07










  • HI folks, thanks for the replys. @Eva Why should I add an array-bracket to the name?
    – Peter
    Nov 20 at 12:16










  • If ever you have input fields with the same name, adding an "array-bracket" will store it in an array. Without it, serialize will use the last input value.
    – claw68
    Nov 20 at 12:48


















  • The important parts we need to see here is the string generated from serialize() and your PHP.
    – Rory McCrossan
    Nov 20 at 10:02










  • How is your html? The name attribute should be something like: name="date" instead of only name="date"
    – Eva
    Nov 20 at 10:05












  • please provide your html code
    – Bhoomi patel
    Nov 20 at 10:07










  • HI folks, thanks for the replys. @Eva Why should I add an array-bracket to the name?
    – Peter
    Nov 20 at 12:16










  • If ever you have input fields with the same name, adding an "array-bracket" will store it in an array. Without it, serialize will use the last input value.
    – claw68
    Nov 20 at 12:48
















The important parts we need to see here is the string generated from serialize() and your PHP.
– Rory McCrossan
Nov 20 at 10:02




The important parts we need to see here is the string generated from serialize() and your PHP.
– Rory McCrossan
Nov 20 at 10:02












How is your html? The name attribute should be something like: name="date" instead of only name="date"
– Eva
Nov 20 at 10:05






How is your html? The name attribute should be something like: name="date" instead of only name="date"
– Eva
Nov 20 at 10:05














please provide your html code
– Bhoomi patel
Nov 20 at 10:07




please provide your html code
– Bhoomi patel
Nov 20 at 10:07












HI folks, thanks for the replys. @Eva Why should I add an array-bracket to the name?
– Peter
Nov 20 at 12:16




HI folks, thanks for the replys. @Eva Why should I add an array-bracket to the name?
– Peter
Nov 20 at 12:16












If ever you have input fields with the same name, adding an "array-bracket" will store it in an array. Without it, serialize will use the last input value.
– claw68
Nov 20 at 12:48




If ever you have input fields with the same name, adding an "array-bracket" will store it in an array. Without it, serialize will use the last input value.
– claw68
Nov 20 at 12:48

















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',
autoActivateHeartbeat: false,
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%2f53390456%2fduring-an-ajax-call-some-data-is-lost%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%2f53390456%2fduring-an-ajax-call-some-data-is-lost%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

Costa Masnaga

Fotorealismo

Sidney Franklin