1

Here my ajax request and response,I have around 85 HTML pages with same ajax request.When i work with these files sometimes im getting following error

enter image description here

AJAX

$(document).ready(function(){
    localStorage.setItem('currentPageNo', 9);
    ResetSwiper();
    CheckPageReadCompleted();
    extrapopuptrigger("1");
});


function ResetSwiper() {
    toggle_text = localStorage.getItem("currentBibleVersion");
    myView = $(".scrollpane").data("mobileIscrollview");
    if(toggle_text == "ESV") {
        $(".searchContent").hide();
        $(".esvContent").show();
        setTimeout(function() {
        var text_search = null;
        $(".esvContent").html('Loading...');
        text_search = $(".searchTitle").html();
        xhr = $.ajax({                      
            type: "GET",
            url: "http://www.esvapi.org/v2/rest/verse?key=IP&passage="+text_search+"&include-footnotes=false",
            data:"",
            contentType: "text/html",
            dataType: "text",
            cache: false,
            async: true,
            crossDomain: true,
            success: function(resp) {
                $(".esvContent").html(resp);
                setTimeout(function() {
                    if(myView != null || myView != 'undefined') {
                        myView.refresh();
                    }
                },100);
            },
            error: function(err) {
                var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
            if(is_uiwebview) {
                  natviveAlert("StandFIRM","Unable to connect internet.Please try again!");
            } else {
                window.JSInterface.showAlertDialog("StandFIRM","Unable to connect internet.Please try again!");
            }
            }
        },100);
    });
    } else{
        $(".esvContent").hide();
        $(".searchContent").show();
        myView.refresh();
    }
 }

How can i solve this issue?Can any one please help me to solve

Huangism
  • 16,278
  • 7
  • 48
  • 74
Fazil
  • 1,390
  • 2
  • 13
  • 26

1 Answers1

2

undefined should not have quotes

   if(myView != undefined) {
     myView.refresh();
    }

Edit:

As @filoxo suggested you can use quotes for undefined but you should add typeof before comparison.

   if(typeof myView != 'undefined') {
     myView.refresh();
    }

Check this link

Community
  • 1
  • 1
mrsrinivas
  • 34,112
  • 13
  • 125
  • 125
  • 2
    I might also be nice to note that it *would be* in quotes if using `typeof` ([link](http://stackoverflow.com/questions/2647867/how-to-determine-if-variable-is-undefined-or-null)), and you could also check for a variable value by simply doing `if( myView ){ ... }`. – filoxo Aug 07 '14 at 15:08
  • i changed ,its shows error now with else part myView.refresh(); – Fazil Aug 07 '14 at 15:15
  • @Fazil just only this condition `if(myView != undefined)` in `setTimeout()` – mrsrinivas Aug 07 '14 at 15:19
  • @MRSrinivas i have changed `if(myView != undefined)` in `setTimeout()`.But now error showing with `else` part `myView.refresh();` – Fazil Aug 07 '14 at 15:32
  • by adding `if(typeof myView != 'undefined') { myView.refresh(); }` this in else condition resolve the issue thankx – Fazil Aug 07 '14 at 15:39