วันเสาร์ที่ 29 มิถุนายน พ.ศ. 2562

การใช้ AJAX ใน ASP.NET ร่วมกับ JavaScript and XML โดยการส่งค่าผ่าน URL


<a href="javascript:void(0)" onclick="showHint('ทดสอบๆ')"> บันทึก </a>

<script>
    function showHint(str) {
        if (str.length == 0) {
      alert("ไม่มีข้อความ");
                 return;
   } else {
                            var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = function() {
                         if (this.readyState == 4 && this.status == 200) {
                    alert(this.responseText);
            }
      };
      alert(str);
      xmlhttp.open("GET", "<%= Request.Url.AbsoluteUri%>" + "&xyz=" + str, true); // ค่าที่แอบส่งไปพร้อมกับ URL
      xmlhttp.send();
    }
    }
</script>

ที่มา: https://www.w3schools.com/asp/asp_ajax.asp



ไม่มีความคิดเห็น:

แสดงความคิดเห็น

การใช้ WebClient สำหรับเรียก URL

Dim _url As String = " https :// www . MyDomain . com /?q=ทดสอบ " Dim wc As New System . Net . WebClient () wc . Encodin...