0

I use Facebook JavaScript SDK. I want to know how to post the Javascript variables to another page with GET or POST or any other way. For example i have:

userInfo = document.getElementById('user-info');

How to post it to new page ?

location.href="http://www.walla.com/?info=" + info.id;

Not working

1
  • can you please show whole code ??? Commented Jul 26, 2012 at 5:10

2 Answers 2

1

Better use ajax for this ..

here is an example.

<script type="text/javascript">
$(document).ready(function() {
   $('#submit-btn').click(function() {
     $.ajax({
       type:'POST',  //POST or GET depending if you want to use _GET or _POST in php
       url:'your-page.php', //Effectively the form action, where it goes to.
       data:$('#txtName').val(),  //The data to send to the page (Also look up form serialise)
       success:function(e) {
            // On success this fill fire, depends on the return you will use in your page.
       }
     });
     return false;
   });
});
</script>

<form>
  <input type="text" id="txtName" />
  <input type="submit" id="submit-btn" value="Send" />
</form>

Hope it works for u.

Sign up to request clarification or add additional context in comments.

Comments

0

That looks okay. You should be able to obtain info.id via $_GET['info'] from PHP.

However, that's assuming userInfo is a simple string.

If it isn't, you may have to convert it to string first. One way to do that is through JSON as JSON is decodable at PHP's side using json_decode().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.