I want to send 2 values to php using ajax. When I use one variable, it works fine, but when I use 2 variables, the query no longer works in the php
file.
$.ajax({
url:'page.php?suplier_id='+suplierNameMain+'&quality_id='+qualityNameMain,
method:'GET', success:function(data) {
});
If I use only supplier_id
, everything works great.
P.S qualityNameMain
shows correct value in console.log()
I want to send 2 values to php using ajax. When I use one variable, it works fine, but when I use 2 variables, the query no longer works in the php
file.
$.ajax({
url:'page.php?suplier_id='+suplierNameMain+'&quality_id='+qualityNameMain,
method:'GET', success:function(data) {
});
If I use only supplier_id
, everything works great.
P.S qualityNameMain
shows correct value in console.log()
- Are suplierNameMain and qualityNameMain url encoded? – JanLikar Commented Jan 15, 2013 at 20:55
- nopes, but Sean's Solution is working :) – irshad.ahmad Commented Jan 15, 2013 at 21:03
2 Answers
Reset to default 4I'm sure it's not related, but there is no reason to build your own query string. Use the data
property instead, which as Barmar points out will properly URL encode your parameters:
$.ajax({
url: 'page.php',
data: {
'suplier_id': suplierNameMain,
'quality_id': qualityNameMain
},
success: function(data) {
/* Whatever */
}
});
Note that method
from your example isn't valid for jQuery (there is a type
setting to switch between GET
and POST
), but GET
is the default so you might as well exclude it altogether.
Use .ajax
like this:
$.ajax({
url: 'page.php',
type: 'GET',
data: {'suplier_id': suplierNameMain,
'quality_id': qualityNameMain
}
success: function(data) {
}
);