Ashif Shereef
Ashif Shereef

Reputation: 494

Ajax POST error in firefox

I have two PHP files with one posting via ajax to the other one. The post works great in chrome. But it doesnt work in firefox. A debug with firebug shows "POST error" in red color. I am pasting my codes below.

Ajax:

var data_val={'user_name' : response.name,
            'user_id' : response.id,
         'user_first' : response.first_name,
         'user_email' : response.email,
       'user_birthday': response.birthday,
       'user_location': response.location.name,
       'user_hometown':response.hometown.name,
     'user_bloodGroup':window.bloodGroup,
      'user_bloodRare':window.user_bloodRare,
       'user_phone_no':window.user_phone,   
         };
                $.ajax({
                    type: "POST",   
                    url: "buddha.php", 
                    data: data_val,})
            });

The file into which it is being posted, buddha.php.

$name1 = $_POST['user_name'];
$email1 = $_POST['user_email'];
$birthday1=$_POST['user_birthday'];
$location1=$_POST['user_location'];
$hometown1=$_POST['user_hometown'];
$fbbloodgroup=$_POST['user_bloodGroup'];    
$fbuserid=$_POST['user_id'];
$user_phone=$_POST['user_phone_no'];
$user_bloodRare=$_POST['user_bloodRare'];
$user_email=$_POST['user_email'];

The above ajax is inside a javascript function,

function fetchUserDetail()

It is called in a buttonclick as follows.

<a class="button_for_me" onclick="checkFacebookLogin()" >Register Me </a>

I have to repeat, this works perfectly and pleasantly in chrome. Initially i thought it was the problem of the success alerts shown at he return of the ajax function, but its not.

Upvotes: 0

Views: 394

Answers (2)

user5810512
user5810512

Reputation:

Assuming from your question that "response" is an object returned by FB API call, I would like to say that the problem is with the Facebook API. Sometimes, the user doesn't have value for variables like "Hometown" and "CurrentTown". In that case, the following assign operations in your code would fail.

   'user_location': response.location.name,
   'user_hometown':response.hometown.name,
   'user_bloodGroup':window.bloodGroup,

Upvotes: 1

Kypros
Kypros

Reputation: 2986

Try changing the ajax from:

$.ajax({
                type: "POST",   
                url: "buddha.php", 
                data: data_val,})
        });

to remove the extra closing tags and comma after data_val like

$.ajax({
   type: "POST",   
   url: "buddha.php", 
   data: data_val
});

Check out this jsFiddle i created for you with an event binding on the class to trigger the ajax request when clicked.

Upvotes: 0

Related Questions