0

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()

4

2 に答える 2

4

I'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.

于 2013-01-15T20:56:34.023 に答える
1

Use .ajax like this:

$.ajax({
    url: 'page.php',
    type: 'GET',
    data: {'suplier_id': suplierNameMain, 
           'quality_id': qualityNameMain
           }

    success: function(data) {
    }
 );
于 2013-01-15T20:58:39.997 に答える