Luke
Luke

Reputation: 2486

jquery ajax call empty querystring

So, I am using jquery to make an ajax call to a php script on my server.

For some reason I cannot figure out, however, there is no querystring sent. Using var_dump() on the $_GET object shows that it is an empty string, and Chrome's network activity developer tool indicates no string is sent.

$.ajax({
            "url":"../script/content.php",
            "settings": {
                "dataType":"html",
                "type":"GET",
                "data":{
                    "id":$(this).prop('id')
                }
            }
        }).done( function(msg) {
            //$('#debug').html(msg);
            $('#dialog').html(msg);
            $('#dialog').load(function() {
                $('#close').click(function() {
                    $('#over').fadeOut(fadeTime);
                });
                if ($('#unique') > 0) {
                    $('#unique').load(function(){
                        $('#over').fadeIn(fadeTime);
                    });
                }
                else {
                    $('#over').fadeIn(fadeTime);
                }
            });             
        });

I had tried the ajax call without the quotes where they weren't necessary before hand, and the result was the same... I just put those in because I thought it might be the problem... though I think that in such notation the quotes don't make a difference unless one of the field values is supposed to be a string.

Is there anything clear in that code which might cause a querystring not to be sent? I guess there is a problem with my syntax... I just can't see it.

The #dialog load callback seems to never be called, either... but I guess that is another question.

Upvotes: 0

Views: 1568

Answers (1)

roshan lal
roshan lal

Reputation: 325

Try this

$.ajax({
    //The link we are accessing with params
    url:'http://example.com/script/content.php'
    + '?id='
    + $(this).prop('id'),
    // The type of request.
    type: "get",
    //The type of data that is getting returned.
    dataType: "html",
    error: function(){
    //something here
    },
    success: function( strData ){
    //something here
    }
});

Upvotes: 1

Related Questions