• 09-12-2018, 14:54:03
    #1
    Üyeliği durduruldu
    Şu şekilde yapmaya calısıyorum fakat olmuyor. Elimde 1 adet form bulunmaktadır bu formları post edince ilgili URL'ye valueleri post etmesini istiyorum bir türlü yapamadım.

    <script>
    function SendData() {
      const tkn = document.getElementsByName('tkn').value;
      const http = new XMLHttpRequest();
      const url = 'get_data.php';
      const params = "tkn=" + tkn + "";
      http.open('POST', url, true);
    
      // Send the proper header information along with the request
      http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    
      http.onreadystatechange = function () { // Call a function when the state changes.
        if (http.readyState == 4 && http.status == 200) {
          alert(http.responseText);
        }
      };
      http.send(params);
      console.log(tkn);
    }
    
    </script>
  • 09-12-2018, 15:01:17
    #2
    Dostum function'u çalıştırmamışsın ki?
    $("form.formclassi").submit(function() {
    SendData();
    });
    Bunu script kapanışından önce ekle. Bir de jQuery çağır en başta.
  • 09-12-2018, 15:04:17
    #3
    MeteOguzhan adlı üyeden alıntı: mesajı görüntüle
    Şu şekilde yapmaya calısıyorum fakat olmuyor. Elimde 1 adet form bulunmaktadır bu formları post edince ilgili URL'ye valueleri post etmesini istiyorum bir türlü yapamadım.

    <script>
    function SendData() {
      const tkn = document.getElementsByName('tkn').value;
      const http = new XMLHttpRequest();
      const url = 'get_data.php';
      const params = "tkn=" + tkn + "";
      http.open('POST', url, true);
    
      // Send the proper header information along with the request
      http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    
      http.onreadystatechange = function () { // Call a function when the state changes.
        if (http.readyState == 4 && http.status == 200) {
          alert(http.responseText);
        }
      };
      http.send(params);
      console.log(tkn);
    }
    
    </script>
    document.getElementsByName fonksiyonu sana doğrudan objeyi döndürmez. Objelerin bulunduğu bir array döndürür. Yapman gereken bu array içerisinden objeyi seçmek. Yani örneğin ilk tkn isimli inputu alacaksan;
      const tkn = document.getElementsByName('tkn')[0].value;
    şeklinde bu satırı düzeltmen gerekli.
    Yardımcı olduysam R10+ kullanmayı unutma.
  • 09-12-2018, 15:04:25
    #4
    Üyeliği durduruldu
    Onur89TR adlı üyeden alıntı: mesajı görüntüle
    Dostum function'u çalıştırmamışsın ki?
    $("form.formclassi").submit(function() {
    SendData();
    });
    Bunu script kapanışından önce ekle. Bir de jQuery çağır en başta.
    form submit butonu ile çağırıyorum.

    <input type="submit" id="gonder" value="Kaydet" class=" btn btn-success success-gradient" onclick="SendData()">
  • 09-12-2018, 15:07:19
    #5
    Kimlik doğrulama veya yönetimden onay bekliyor.
    document.getElementsByName('tkn').value;

    yerine

    document.getElementsByName('tkn')[0].value;

    olacak.

    document.getElementsById gibi düşünmüşsün ama ...ByName olunca index no'sunu da belirtmen gerekir.
  • 09-12-2018, 15:17:46
    #6
    Üyeliği durduruldu
    teşekkürler hocam problem böyle çözüldü. Eğer giden postta responsede içerisinde "Success" geçiyorsa şunu yap nasıl yapabilirim peki if http.response == "success" kullanıyorum olmuyor cunku sadece success yazarsa olur demek diye biliyorum http response yerine öyle birşey varmı responsede şu kelime geçiyorsa diye

    Cappystarj0e adlı üyeden alıntı: mesajı görüntüle
    document.getElementsByName('tkn').value;

    yerine

    document.getElementsByName('tkn')[0].value;

    olacak.

    document.getElementsById gibi düşünmüşsün ama ...ByName olunca index no'sunu da belirtmen gerekir.
  • 09-12-2018, 15:25:11
    #7
    if (http.responseText.indexOf("success") !== -1)

    ise şunu şunu yap diyebilirsin.

    "http.responseText içinde success geçiyorsa" anlamına gelir.

    bu arada indexOf() büyük-küçük harfe duyarlıdır.
    if'e "Success" yazıp da, cevap "success" gelirse doğru çalışmaz.

    örnek deneme:
    https://www.w3schools.com/jsref/tryi...yjsref_indexof
  • 09-12-2018, 15:30:07
    #8
    Üyeliği durduruldu
    Cappystarj0e adlı üyeden alıntı: mesajı görüntüle
    if (http.responseText.indexOf("success") !== -1)

    ise şunu şunu yap diyebilirsin.

    "http.responseText içinde success geçiyorsa" anlamına gelir.

    bu arada indexOf() büyük-küçük harfe duyarlıdır.
    if'e "Success" yazıp da, cevap "success" gelirse doğru çalışmaz.

    örnek deneme:
    https://www.w3schools.com/jsref/tryi...yjsref_indexof


    teşekkürler hocam 2 problemde çözüldü, sizin gibi yardımsever zor bulunuyor sağolun