'Sending data to salesforce Web to lead form

I have created an app on fb, and want people to sign up for it. I want whoever signs up, the details should be sent to my Salesforce form using Web-to-lead form. Salesforce provides a code(javascript form) to send data. This code works fine if I compile it on my browser. But if I paste this code in my app on facebook, the entries are not posted to salesforce. Can somebody suggest what changes should be made? Can this be done using JSON and AJAX?

I wrote this code (referred the link given in comments), but the code does not seem to be work. This code does not give any output!

    <html>
    <script type="text/javascript">
    function funct()
    {
    var first_name= myForm.first_name.value;
    var last_name=myForm.last_name.value;
    var email=myForm.email.value;
    alert(first_name);
    var $form = $(myForm, {
        method: "POST",
        action: "https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8",
        target: "my-iframe"
    }).appendTo("body");

var $iframe = $("<iframe>", {
        name: "my-iframe"
    }).bind( "load", function () {
        $('.error').hide();
        $('.success').slideDown('slow');
        $('form#callToAction').fadeOut('slow');
        $iframe.remove();
        $form.remove();
    }).appendTo("body");

    $.each(("first_name=" + first_name + "&last_name=" + last_name + "&email=" + email + "&oid"= + "00Di0000000JbNJ").split("&")), function (index, value) {
        var pair = value.split("=");
        $form.append("<input>", {
            type: "hidden",
            name: pair[0],
            value: pair[1]
        });
    });

    $form.submit();

    }
    </script>
    <b> You just need to share your name and email address!! </b> <br>
    <META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">

    <!--<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">-->

    <input type=hidden name="oid" value="00Di0000000JbNJ">
    <input type=hidden name="retURL" value="http://">


     <form name="myForm" onSubmit="return funct()" >
    <label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
    <label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
    <label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>
    <input type="Submit" onSubmit="funct();" value="Submit"></input>
    </form>


Solution 1:[1]

You can do this. I have posted to Salesforce web to lead using just an HTTP post via C# so doing it with an ajax call should work. Check out this post in the salesforce forums and see if it helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ToddB