הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   עזרה ב jquery (https://hosts.co.il/forums/showthread.php?t=109651)

RazRaz 07-12-15 13:08

עזרה ב jquery
 
שלום,
יש לי את הקוד הבא:
הסבר קצר -
יש 4 סלקטים שבכל בחירה על ידי ONCHANE מופעלת פונקציה שמכניסה את ה val לתוך הURL מתוך API של ויקיפדיה .

הבעיה -
בכל פעם שאני אבחר בסלקט אחר אני רוצה שיופיע למשל ה title .
wiki.query.pages[number].title
הבעיה היא שה number כל פעם משתנה אני רוצה לגשת אליו מבלי לדעת אותו מראש.

HTML קוד:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
        <meta charset="UTF-8">
        <title></title>
        <style>
        .textim {
                width: 500px;
                height: 500px;
                border: 2px solid brown;
                float: left;
        }
        </style>
</head>
<body>

<select onchange="abc()">
  <option value="israel" >Israel</option>
  <option value="england">England</option>
  <option value="russia">Russia</option>
  <option value="spain">Spain</option>
</select>

<div class="textim"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
function abc() {
        var ttls = $( "select" ).val()
        var url = 'https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles='+ttls + "&callback=?";
        $.getJSON( url, function ( wiki ) {
               
                console.log(wiki);
       
               
                console.log(wiki.query.normalized[0].to);
                $('.textim').text( wiki.query.normalized[0].to );
               
        });
}
</script>


</body>
</html>


תודה לכולם מראש


כל הזמנים הם GMT +2. הזמן כעת הוא 09:18.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ