How can I implement a jquery ajax form which requests information from a web api via a php request?

Posted by Jacob Schweitzer on Stack Overflow See other posts from Stack Overflow or by Jacob Schweitzer
Published on 2010-04-30T21:35:13Z Indexed on 2010/04/30 21:37 UTC
Read the original article Hit count: 243

Filed under:
|

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!!

© Stack Overflow or respective owner

Related posts about jquery-ajax

Related posts about php