7

i am trying to pass the values of accesstoken and pageid inside the url that i use. Any ideas how to do it correctly?

<script type="text/javascript">   
function makeUrl() {
    var accesstoken = "12345679|bababashahahhahauauuaua";
    var pageid =  "<?php echo $page_id;?>";
 $.ajax(
  {
    url: 'https://graph.facebook.com/?pageid/?access_token='+pageid+accesstoken,
 statusCode: {......
1

4 Answers 4

10

Change

url: 'https://graph.facebook.com/?pageid/?access_token='+pageid+accesstoken,

to

url: 'https://graph.facebook.com/?pageid='+pageid+'&access_token='+accesstoken,
Sign up to request clarification or add additional context in comments.

1 Comment

Hi,i still facing a problem to pass the pageid var inside the ajax. I am taking an error message at the console """GET XHR graph.facebook.com """ Any help?
2

You can also use the "data" setting. This will convert it to a query string.

<script type="text/javascript">   
function makeUrl() {
    var accesstoken = "12345679|bababashahahhahauauuaua";
    var pageid =  "<?php echo $page_id;?>";
 $.ajax(
  {
    url: 'https://graph.facebook.com/',
    data: 'pageid='+pageid+'&access_token='+accesstoken
 statusCode: {......

Comments

1
 'https://graph.facebook.com/?pageid='+pageid+'&access_token='+accesstoken

Comments

0

You can create your url using:

function makeUrl() {
  var accesstoken = '12345679|bababashahahhahauauuaua';
  var pageid =  'example'
  return 'https://graph.facebook.com/?pageid=' + pageid + '&access_token=' + accesstoken;
}

And then pass it to your AJAX function.

function doAjax(_url) {
  return $.ajax({
    url: _url,
    type: 'GET'
  });
}

doAjax(makeUrl());

And now an elegant way to handle your success callback:

doAjax(makeUrl()).success(function() {
  // this will be executed after your successful ajax request
});

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.