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?
javascript php jquery sql ajax
add a comment |
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?
javascript php jquery sql ajax
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
add a comment |
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?
javascript php jquery sql ajax
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
javascript php jquery sql ajax
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
add a comment |
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
add a comment |
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);
});
};
No such method asJSON.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
add a comment |
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);
});
};
No such method asJSON.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
add a comment |
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);
});
};
No such method asJSON.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
add a comment |
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);
});
};
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);
});
};
edited Nov 11 at 12:06
answered Nov 11 at 11:46
Edwin Dijas Chiwona
34117
34117
No such method asJSON.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
add a comment |
No such method asJSON.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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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