Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1048067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:23:56+00:00 2026-05-16T16:23:56+00:00

function addFav(id){ $.ajax({ url: misc/favAdd.php, type: POST, data: { mode: ‘ajax’, user: id}, dataType:

  • 0
function addFav(id){
    $.ajax({
      url: "misc/favAdd.php",
      type: "POST",
      data: { mode: 'ajax', user: id},
        dataType: 'json',
      success: function(data, status){
                    if(typeof(data.error) != 'undefined') {
                        if(data.error != '')
                            alert(data.error);
                    } else {
           $('a#fav')
                 .addClass('active')
                 .attr('title','[-] Remove as favorite')
                 .unbind('click')
                             .bind('click', function() { removeFav(id); })
           ;
                jGrowlTheme('wallPop', 'mono', '[+] Favorit', 'Du har nu lagt till denna profil som favorit', 'images/addFavorit_hover2.png', 1000);
      }
      }
    });
}

I have this, and i wish to alert the data.error, if it gets any error response, and that works. But now, if i dont have any data.error it doesnt run the addClass and stuff thats after }else{ ?

What have i done wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:23:57+00:00Added an answer on May 16, 2026 at 4:23 pm

    What if you used this instead?

    function addFav(id) {
        $.ajax({
            url: "misc/favAdd.php",
            type: "POST",
            data: {
                mode: 'ajax',
                user: id
            },
            dataType: 'json',
            success: function(data, status) {
                if (data.error !== undefined && data.error != '') {
                    alert(data.error);
                } else {
                    $('a#fav')
                    .addClass('active')
                    .attr('title', '[-] Remove as favorite')
                    .unbind('click')
                    .bind('click',
                    function() {
                        removeFav(id);
                    });
                    jGrowlTheme('wallPop', 'mono', '[+] Favorit', 'Du har nu lagt till denna profil som favorit', 'images/addFavorit_hover2.png', 1000);
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
    }
    

    I suspect what is happening is your having a failure getting any (valid) data, and since you haven’t defined an error handler, the response is just getting dropped on the floor. Your test for error relies on their being data to begin with and so will only trigger if you get back valid data that contains an ‘error’ property in the object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function checkuser(user) { var ret = false; $.ajax({ type:'POST', url:'user.php', async:false, data:{'user':user}, success:function (data)
I have the following jQuery/ajax script: jQuery(input.button).click(function(){ jQuery.ajax({ url: 'addfav.php', type: 'POST', data: {'id':jQuery(this).closest(div).attr(id),is_ajax:
function stationMenu($scope){ $.ajax({ url: /users/station_names_ajax, type: POST, success: function(data){ $scope.phones = [ {name: Nexus
function contentDisp() { $.ajax({ url : a2.php, success : function (data) { $(#contentArea).html(data); }
$(document).ready(function() { $('a#fav').bind('click', function() { addFav(<?php echo $showUP[uID]; ?>); }); }); function addFav(id){ $.ajax({
function get() { $.post( 'postchatfame.php', { comment: postchatfamemsg.comment.value, userid: postchatfamemsg.userid.value }, function(output) { $('#walls').html(output).show();
$(document).ready(function() { $('a#fav').bind('click', addFav(<?php echo $showUP[uID]; ?>)); }); was before $(document).ready(function() { $('a#fav').bind('click', addFav);
$(document).ready(function() { $('a#fav').bind('click', function() { addFav(<?php echo $showUP[uID]; ?>); }); }); I need to
function json (url){ $.getJSON(url, function(data) { return data; }) } this function don't see
function getWindowsUserName() { var WinNetwork = new ActiveXObject(WScript.Network); var urlToSite = http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS= + WinNetwork.UserName;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.