POST variable always stays empty











up vote
-1
down vote

favorite












This is the method in which i manage the data send with jquery.ajax. By default is send an empty string and on each change i watch the change on the input and resend it. Through console things are good but in php $this->searchField always has the value of an empty string



function checkInfo(){
if(isset($_POST['searchField'])){
$this->searchField = json_decode($_POST['searchField']);

if ($this->searchField != ""){
$this->query = "SELECT * FROM myguests WHERE firstName like '%".$searchField."%'";
}
else if ($this->searchField == "") {
$this->query = "SELECT * FROM myguests ORDER BY id";
}
$this->tableDisplay();
exit();
}
else{
return "error";
}
}


This is my jquery ajax function :



function searchGuests(users){
var data = {
"searchField": users
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};


Any idea what I am missing?










share|improve this question






















  • what does the users variable holding?
    – Ali
    Nov 11 at 11:50






  • 1




    You aren't sending any JSON so no need to use json_decode()
    – charlietfl
    Nov 11 at 11:54















up vote
-1
down vote

favorite












This is the method in which i manage the data send with jquery.ajax. By default is send an empty string and on each change i watch the change on the input and resend it. Through console things are good but in php $this->searchField always has the value of an empty string



function checkInfo(){
if(isset($_POST['searchField'])){
$this->searchField = json_decode($_POST['searchField']);

if ($this->searchField != ""){
$this->query = "SELECT * FROM myguests WHERE firstName like '%".$searchField."%'";
}
else if ($this->searchField == "") {
$this->query = "SELECT * FROM myguests ORDER BY id";
}
$this->tableDisplay();
exit();
}
else{
return "error";
}
}


This is my jquery ajax function :



function searchGuests(users){
var data = {
"searchField": users
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};


Any idea what I am missing?










share|improve this question






















  • what does the users variable holding?
    – Ali
    Nov 11 at 11:50






  • 1




    You aren't sending any JSON so no need to use json_decode()
    – charlietfl
    Nov 11 at 11:54













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











This is the method in which i manage the data send with jquery.ajax. By default is send an empty string and on each change i watch the change on the input and resend it. Through console things are good but in php $this->searchField always has the value of an empty string



function checkInfo(){
if(isset($_POST['searchField'])){
$this->searchField = json_decode($_POST['searchField']);

if ($this->searchField != ""){
$this->query = "SELECT * FROM myguests WHERE firstName like '%".$searchField."%'";
}
else if ($this->searchField == "") {
$this->query = "SELECT * FROM myguests ORDER BY id";
}
$this->tableDisplay();
exit();
}
else{
return "error";
}
}


This is my jquery ajax function :



function searchGuests(users){
var data = {
"searchField": users
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};


Any idea what I am missing?










share|improve this question













This is the method in which i manage the data send with jquery.ajax. By default is send an empty string and on each change i watch the change on the input and resend it. Through console things are good but in php $this->searchField always has the value of an empty string



function checkInfo(){
if(isset($_POST['searchField'])){
$this->searchField = json_decode($_POST['searchField']);

if ($this->searchField != ""){
$this->query = "SELECT * FROM myguests WHERE firstName like '%".$searchField."%'";
}
else if ($this->searchField == "") {
$this->query = "SELECT * FROM myguests ORDER BY id";
}
$this->tableDisplay();
exit();
}
else{
return "error";
}
}


This is my jquery ajax function :



function searchGuests(users){
var data = {
"searchField": users
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};


Any idea what I am missing?







javascript php jquery sql ajax






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 11:31









juxhin bleta

598




598












  • what does the users variable holding?
    – Ali
    Nov 11 at 11:50






  • 1




    You aren't sending any JSON so no need to use json_decode()
    – charlietfl
    Nov 11 at 11:54


















  • what does the users variable holding?
    – Ali
    Nov 11 at 11:50






  • 1




    You aren't sending any JSON so no need to use json_decode()
    – charlietfl
    Nov 11 at 11:54
















what does the users variable holding?
– Ali
Nov 11 at 11:50




what does the users variable holding?
– Ali
Nov 11 at 11:50




1




1




You aren't sending any JSON so no need to use json_decode()
– charlietfl
Nov 11 at 11:54




You aren't sending any JSON so no need to use json_decode()
– charlietfl
Nov 11 at 11:54












1 Answer
1






active

oldest

votes

















up vote
-1
down vote













Try encoding the users to a string before sending it over.



function searchGuests(users){
var data = {
"searchField": JSON.stringify(users);
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};





share|improve this answer























  • No such method as JSON.encode() and the idea doesn't make sense either. jQuery uses $.param() to serialize objects by default
    – charlietfl
    Nov 11 at 11:52












  • I solved it indeed it didn't needed to be json_decode -ed
    – juxhin bleta
    Nov 11 at 11:52










  • confused it with php json_encode. it is JSON.stringify
    – Edwin Dijas Chiwona
    Nov 11 at 12:02










  • please share your answer. Thanks
    – Edwin Dijas Chiwona
    Nov 11 at 12:07











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%2f53248287%2fpost-variable-always-stays-empty%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
-1
down vote













Try encoding the users to a string before sending it over.



function searchGuests(users){
var data = {
"searchField": JSON.stringify(users);
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};





share|improve this answer























  • No such method as JSON.encode() and the idea doesn't make sense either. jQuery uses $.param() to serialize objects by default
    – charlietfl
    Nov 11 at 11:52












  • I solved it indeed it didn't needed to be json_decode -ed
    – juxhin bleta
    Nov 11 at 11:52










  • confused it with php json_encode. it is JSON.stringify
    – Edwin Dijas Chiwona
    Nov 11 at 12:02










  • please share your answer. Thanks
    – Edwin Dijas Chiwona
    Nov 11 at 12:07















up vote
-1
down vote













Try encoding the users to a string before sending it over.



function searchGuests(users){
var data = {
"searchField": JSON.stringify(users);
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};





share|improve this answer























  • No such method as JSON.encode() and the idea doesn't make sense either. jQuery uses $.param() to serialize objects by default
    – charlietfl
    Nov 11 at 11:52












  • I solved it indeed it didn't needed to be json_decode -ed
    – juxhin bleta
    Nov 11 at 11:52










  • confused it with php json_encode. it is JSON.stringify
    – Edwin Dijas Chiwona
    Nov 11 at 12:02










  • please share your answer. Thanks
    – Edwin Dijas Chiwona
    Nov 11 at 12:07













up vote
-1
down vote










up vote
-1
down vote









Try encoding the users to a string before sending it over.



function searchGuests(users){
var data = {
"searchField": JSON.stringify(users);
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};





share|improve this answer














Try encoding the users to a string before sending it over.



function searchGuests(users){
var data = {
"searchField": JSON.stringify(users);
};
console.log(data);
$.ajax({
type: "POST",
dataType: "text",
url: "controllers/manageTable.php",
data: data
})
.done(function(tr) {
$("#tableBody").empty();
$("#tableBody").append(tr);
})
.fail(function(error){
console.log(error);
});
};






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 12:06

























answered Nov 11 at 11:46









Edwin Dijas Chiwona

34117




34117












  • No such method as JSON.encode() and the idea doesn't make sense either. jQuery uses $.param() to serialize objects by default
    – charlietfl
    Nov 11 at 11:52












  • I solved it indeed it didn't needed to be json_decode -ed
    – juxhin bleta
    Nov 11 at 11:52










  • confused it with php json_encode. it is JSON.stringify
    – Edwin Dijas Chiwona
    Nov 11 at 12:02










  • please share your answer. Thanks
    – Edwin Dijas Chiwona
    Nov 11 at 12:07


















  • No such method as JSON.encode() and the idea doesn't make sense either. jQuery uses $.param() to serialize objects by default
    – charlietfl
    Nov 11 at 11:52












  • I solved it indeed it didn't needed to be json_decode -ed
    – juxhin bleta
    Nov 11 at 11:52










  • confused it with php json_encode. it is JSON.stringify
    – Edwin Dijas Chiwona
    Nov 11 at 12:02










  • please share your answer. Thanks
    – Edwin Dijas Chiwona
    Nov 11 at 12:07
















No such method as JSON.encode() and the idea doesn't make sense either. jQuery uses $.param() to serialize objects by default
– charlietfl
Nov 11 at 11:52






No such method as JSON.encode() and the idea doesn't make sense either. jQuery uses $.param() to serialize objects by default
– charlietfl
Nov 11 at 11:52














I solved it indeed it didn't needed to be json_decode -ed
– juxhin bleta
Nov 11 at 11:52




I solved it indeed it didn't needed to be json_decode -ed
– juxhin bleta
Nov 11 at 11:52












confused it with php json_encode. it is JSON.stringify
– Edwin Dijas Chiwona
Nov 11 at 12:02




confused it with php json_encode. it is JSON.stringify
– Edwin Dijas Chiwona
Nov 11 at 12:02












please share your answer. Thanks
– Edwin Dijas Chiwona
Nov 11 at 12:07




please share your answer. Thanks
– Edwin Dijas Chiwona
Nov 11 at 12:07


















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%2f53248287%2fpost-variable-always-stays-empty%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

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma