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

2
  • Are suplierNameMain and qualityNameMain url encoded? Commented Jan 15, 2013 at 20:55
  • nopes, but Sean's Solution is working :) Commented Jan 15, 2013 at 21:03

2 Answers 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.

Sign up to request clarification or add additional context in comments.

3 Comments

It very well could be related. This will ensure that the values are properly URL-encoded.
No problem. As an aside, supplier has two 'p's, not one.
lol, actually this mistake occurred right from the start and i didn't notice in the first place. when i figured that out, the project was too big to be edited, so as a matter of consistency, i left it this way :p
1

Use .ajax like this:

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

    success: function(data) {
    }
 );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.