2017-10-26 14 views
7

पढ़ें। यह पूरी तरह से काम कर रहा है, लेकिन किसी कारण सेjQuery/जावास्क्रिप्ट किसी कारण मैं इस 'बात'</p> <p>साथ अटक गया आप मैं count.txt को पढ़ने के लिए कोशिश करना चाहता हूँ देख सकते हैं के लिए एक स्थानीय पाठ फ़ाइल

alert(code); 

यह कोई मतलब नहीं है, क्योंकि मैं चेतावनी (संख्या) से पहले फोन करता हूँ

alert("The number can't be smaler then 0"); 

मेरे लिए के बाद आ रहा है चेतावनी ("संख्या ...") कोई विचार क्यों jQuery चेतावनी (चेतावनी) को दूसरी चेतावनी के बाद बुलाया जाता है?

function leftFunction() { 
    jQuery.get('count.txt', function(data) { 
     var count = data; 
     alert(count); 
    }); 
    scrolling = true; 
    if(number == 0) { 
     alert("The number can't be smaler then 0"); 
     return; 
    } 
    number--; 
    document.getElementById("myImage").src = "latest" + number + ".jpg"; 
} 
+6

कि सिंक/async किया जा रहा से संबंधित है। इसे देखें: https://stackoverflow.com/questions/27012556/make-synchronous-function-in-javascript –

+2

['jQuery.get()'] (http://api.jquery.com/jquery.get/) कॉलबैक फ़ंक्शन एसिंक्रोनस _ है "अगर अनुरोध पहले से पूरा हो चुका है, तो कॉलबैक तुरंत निकाल दिया जाता है।" _ – guest271314

+0

मेरी मदद करने के लिए बहुत बहुत धन्यवाद :) –

उत्तर

3

जैसा कि लाल एफएक्स टिप्पणियों में कहता है, यह जावास्क्रिप्ट से असीमित होने से संबंधित है। इस के बजाय की तरह कुछ का प्रयास करें:

function leftFunction() { 
    jQuery.get('count.txt', function(data) { 
     var count = data; 
     alert(count); 
    }).done(function() { 
     scrolling = true; 
     if (number == 0) { 
      alert("The number can't be smaler then 0"); 
      return; 
     } 
    }); 
    number--; 
    document.getElementById("myImage").src = "latest" + number + ".jpg"; 
} 

संदर्भ: https://api.jquery.com/jquery.get/

+0

स्निपेट के लिए बहुत बहुत धन्यवाद :) –

संबंधित मुद्दे

 संबंधित मुद्दे