Diafol, anybody pls help.

i have this javascript code

<script>

            FB.init({
              appId  : '00000000000000',
              frictionlessRequests: true,
            });

          function sendRequestToRecipients() {
            var user_ids = document.getElementsByName("user_ids")[0].value;
            FB.ui({method: 'apprequests',
              message: 'Great App',
              to: user_ids, 
            }, requestCallback);
          }

          function sendRequestViaMultiFriendSelector() {
            FB.ui({method: 'apprequests',
              message: 'My Great Request'
            }, requestCallback);
          }

          function requestCallback(response) {
            console.log(response);
            for (var i = 0; i < response.to.length; ++i)
            {
            alert(response.to[i]);
            }
      }
      </script>

Now all i want to do is get the value that is in this

alert(response.to[i]);

and pass it to php and insert it into mysql for future use. Am very bad at javascript, pls help.

Well I'm not great at PHP but here's a start...

To pass a value client side to server side, you have two common options...

Send the value to a PHP script using Ajax or save the value in a input element of type hidden. This hidden element's value can be capture duiring the post event when a user clicks on a submit button for example.

Check out doing this with a jQuery POST request.

thanks for you time, any examples to point to will be a grate start. thx

Using javaScript Ajax is fairly easy but if you don't have experience with javascript, you could use jQuery's post method which is really javascript Ajax on the backend but a lot less code.

To use jQuery, you have to include the source of the library in your head section.

Then in your javascript, use the post method where it logically makes sense.

 $.post( "test.php", { param: response.to[i]} );

Your PHP page needs to accept this posted data and process it, save to the DB, etc...

It's very challenging to give you a better example based on the info you provided.

I think it would be better for you to go back and read up on posting data to a PHP page using javascript/jQuery if what you are looking for is sending data back to the server without having to reload the page.

jQuery documentation: http://api.jquery.com/jquery.post/

Try this, change the #submit to match your button's name or id and also the post URL :

<script type="text/javascript">
      $(document).ready(function(){
        $("#submit").click(function(){
          $.ajax({
        type: "POST",
        async: false,//here you are synchrone
        url: "", //Put your URL here
        success: function(data) {
            //echo data from server side
          });
        });
      });
</script>

Buzz back if it's working or if there's error, do specify the error...

thank you imchivaa for your help. but is there a way i can nest the ajax script you posted with my script above?

i want to know if i can nest it like this

function requestCallback(response) {
            console.log(response);
            for (var i = 0; i < response.to.length; ++i)
            {
            //alert(response.to[i]);
             $.ajax({
        type: "POST",
            data: {
       zxy: response.to[i];}
}).done(function( msg )
      {
       alert( "Data Saved: " + msg );// see alert is come or not
     });
            }
      }});

i finally got it. Here is my solution

` <div id="facebook_invite"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>

      <script>

        FB.init({
          appId  : 'xxxxxxxxxxxx',
          frictionlessRequests: true,
        });

      function sendRequestToRecipients() {
        var user_ids = document.getElementsByName("user_ids")[0].value;
        FB.ui({method: 'apprequests',
          message: 'Great App',
          to: user_ids, 
        }, requestCallback);
      }

      function sendRequestViaMultiFriendSelector() {
        FB.ui({method: 'apprequests',
          message: 'xxxxxxxx Request'
        }, requestCallback);
      }

    function requestCallback(response){
        console.log(response);
        for (var i = 0; i < response.to.length; ++i)
        { 
     var lapaz = response.to[i];

        $.ajax({
          type: "POST",
          url: "fb.php",
          data: "user_ids="+ lapaz,
          success:function(data){
                             location.reload(); 
                          }

        });
        }
      }

</script>`

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.