1

I have this code:

meJi = 33;
$.ajax({
type: "POST",
url: mega,
data: string,
beforeSend: function() {
    $('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast');
},
complete: function() {
    $('#loading').fadeOut('fast');
},
success: function(msg) {
    loading_hide();
    f = (msg).length;
    if (f <= 1250) {
        alert("su busqueda no presenta resultados");
        code(3);

        else {
            $("#container").html(msg);
            fdemandados();
        }
    }
});
function code(ig) {
    console.log(img);
    meJi = ig;
}

$("#select_comprobar3").on('click', function(event) {
    tacuba = $("#amazon").val();
    ca = "2";
    dan = "g";
    if (meJi ==3) {
        avisobusqueda2 = $("#avisofiltro").html("zzzFiltro activado Busqueda por la palabra: " + tacuba + " - clic para quitar ").fadeIn('slow');
    } else {}
    if (!tacuba) {
        alert("Debe ingresar una palabra");
    } else {
        lor = tacuba;
        var page = "1";
        loadData(page, dan, lor);
    }
    event.stopImmediatePropagation();
    return false;
});

the problem is this:

if (meJi==3) {

I don't know why but meJi variable never changes to 3 so the conditional always assume that meJi is 33.

edit: Im change the conditional part but the problem still exist.

6
  • 1
    Do you get the alert "su busqueda no presenta resultados"? Commented Apr 10, 2013 at 17:25
  • In this code it will never get to "3", but you are also comparing String with Integer. Commented Apr 10, 2013 at 17:25
  • @Niels "3" == 3, "3" !=== 3 Commented Apr 10, 2013 at 17:26
  • the else part should be after the if statement, not inside Commented Apr 10, 2013 at 17:26
  • @DaveNewton I am aware it returns true, but it's kinda nasty. Commented Apr 10, 2013 at 17:27

1 Answer 1

5

In

function code(ig){
  console.log(img);
  meJi = ig;
}

Should it not be console.log(ig);? How you have it would cause an error (with img not defined) and therefore, meJi would not get set.

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

7 Comments

This would NOT cause an error. It would just output undefined in the console.
@Orin yes, but this is not the question. Is another mistake.
@Steve If img is not defined it will throw a RefereneceError and prevent meJi from being set.
@Steve It would throw ReferenceError: img is not defined error, not undefined. Unless I missed where it is declared. Meaning it would never set the variable to 3.
@aug it changes nothing. I am correct that error and the problem still exist.
|

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.