views:

44

answers:

1

I'm trying to implement a simple api request to the SEOmoz linkscape api. It works if I only use the php file but I want to do an ajax request using jquery to make it faster and more user friendly. Here is the javascript code I'm trying to use:

$(document).ready(function(){

    $('#submit').click(function() {
    var url=$('#url').val();
            $.ajax({
                type: "POST",
                url: "api_sample.php",
                data: url,
                cache: false,
                success: function(html){
                    $("#results").append(html);
            }
        });
    });
});

And here is the part of the php file where it takes the value:

$objectURL = $_POST['url'];

I've been working on it all day and can't seem to find the answer... I know the php code works as it returns a valid json object and displays correctly when I do it that way. I just can't get the ajax to show anything at all!!

+1  A: 

...data: 'url='+encodeURIComponent(url),

webdestroya
The url is already encoded properly in the php file like so: .urlencode($objectURL).
Jacob Schweitzer
Then `'url='+url`
webdestroya
Still didn't work.. maybe I'll try again without jquery or something. I'm not sure what to do at this point, ajax forms aren't so easy as i've read in a lot of places. Maybe for sending an email its not so difficult but I haven't seen any articles about something like this.
Jacob Schweitzer