1

I'm using Ajax to submit hybridauth, but the submission is failing straight off, has anyone tried anything like this before? See below for code examples.

(login.php is unaltered but send results to handler file that send the results back on success)

$(".socialClient").click(function(){
    var socID = $(this).attr("id");  //the ID for the social media provider image is the name of the provider
    $.ajax({
        type: "GET",
        url: "hybridauth/login.php",
            cache: false,
            data: {provider:socID},
        //enctype: "multipart/form-data",
        dataType: "text",
        success: function(data){
            //handle response, user info and such
        },
        error:function (xhr, ajaxOptions, thrownError){
            alert("Social media logon failed. Error code:" +thrownError);
        }
    });
});
Jose Gómez
  • 3,110
  • 2
  • 32
  • 54
VikingGoat
  • 387
  • 3
  • 8
  • 30
  • What is your browser saying about the auth, in firefox use firebug in chrome open the inspector and watch the conections to the server see what info is being given about the connection then update your question without knowing whats causing the error we can't help you it could be any thing from a 500 error (script on server failed) or 404(file not found) – Barkermn01 Nov 23 '12 at 23:12

2 Answers2

0

Can you test what you are receiving in the login.php file? You may already have tried this, but JIC, edit login.php to echo back the result it receives, like this:

LOGIN.PHP (at very top of file):

<?php
$p = $_POST['provider']; //this may not be your post variable name
echo $p;
die();

And then in your ajax success function, alert yourself what you are receiving:

success: function(data) {
    alert(data);
}

A good first step to find out if you're getting what you expect.

cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • 2
    Sorry, I stepped away from this project out of frustration and returned to it just recently, a little wiser, but no nearer a solution. I did find that login.php is receiving the appropriate Provider info, but somewhere along the line it's failing and causing a dialog window to simply reopen on top of itself. – VikingGoat Apr 16 '13 at 20:18
  • I have actually just now managed to narrow it down to an issue with isConnectedWith() (its returning no value what so ever), which shouldn't be an issue since I really am connected with what I'm testing with and another version of the site works just fine. – VikingGoat Apr 17 '13 at 15:41
  • 1
    VikingGoat, did you resolve this? I mean the popup dialog, because I can not either :( – InsaurraldeAP Jun 27 '14 at 01:32
0

Since authentication requires redirecting the user to the provider, it won't work with AJAX calls. The backend script will die() in the Redirect function.

For an alternative solution, check this approach: https://stackoverflow.com/a/29891358/1816603

Community
  • 1
  • 1
Jose Gómez
  • 3,110
  • 2
  • 32
  • 54