Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery ajax

    $.ajax({
        url: url,
        dataType: "json",
        type: "Post",
        async: true,
        data: { },
        success: function (data) {
           
        },
        error: function (xhr, exception) {
            var msg = "";
            if (xhr.status === 0) {
                msg = "Not connect.
 Verify Network." + xhr.responseText;
            } else if (xhr.status == 404) {
                msg = "Requested page not found. [404]" + xhr.responseText;
            } else if (xhr.status == 500) {
                msg = "Internal Server Error [500]." +  xhr.responseText;
            } else if (exception === "parsererror") {
                msg = "Requested JSON parse failed.";
            } else if (exception === "timeout") {
                msg = "Time out error." + xhr.responseText;
            } else if (exception === "abort") {
                msg = "Ajax request aborted.";
            } else {
                msg = "Error:" + xhr.status + " " + xhr.responseText;
            }
           
        }
    }); 
Comment

jquery ajax

$.ajax({
  method: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });
Comment

ajax jquery

$(document).ready(function(){
$('#btnadd').click(function(e){
    e.preventDefault();
   var nm =$('#nameid').val();
   var em =$('#emailid').val();
   var pas =$('#passid').val();
   var  mydata={name:nm,email:em,password:pas};
 $.ajax({
    url: 'insert.php',
    method:'post',
    data:mydata,
    success:function(data){
      console.log(nm);  
    }
 });
});
});
Comment

jquery ajax

$.ajax('[URL]', {
  method: 'POST',
  dataType: 'json',
  timeout: 5000
}).then(function (responseJSON) {
  console.log(responseJSON);
}).catch(function(err){
  console.log('Caught an error:' + err.statusText);
});
Comment

Jquery ajax

// this page loads the file "data.txt" when the button is clicked.
// This file is index.php.
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script>
    $(document).ready(function(){
      $("#btn").click(function() {
        $("#content").load("data.txt");
      });
    })
  </script>
</head>

<body>
  <div id="content"></div>
  <br>
  <button id="btn">Press Me</button>
</body>
</html>
Comment

jquery ajax

// jquery ajax
<script>
        let categoryName = $('select[name="category"]')
        let subcategory = $('select[name="subcategory"]')
        categoryName.on('change',function(){
                let myUrl = `{{ route('products.ajax', ':id') }}`
                let id = $(this).val()
                let newUrl = myUrl.replace(':id', id);
                $.ajax({
                    url: newUrl,
                    dataType: 'json',
                    type: 'get',
                    success: function (response){
                        let options =[]
                        response.map(element => {
                            let option = `<option value="${element.id}">${element.name}</option>`;
                            options.push(option)
                        })
                        subcategory.html('')
                        subcategory.html(options)
                    },
                    error: function(data){
                       let option = `<option disable>${data.responseText}</option>`
                       
                       subcategory.html('')
                        subcategory.html(option)
                    }
                })
            })
        </script>        
    
Comment

jquery ajax

//jquery ajax
// controller
public function product($id)
    {
        $category = SubCategory::where('category_id', $id)
            ->select('id', 'category_id', 'name')
            ->get();

        if (count($category) > 0) {
            return $category;
        }else{
            return 'no sub category';
        }
    }

// url 
Route::get('/product/{id}', 'product')->name('ajax.product');

// product page
        <script>
            let categroy = $('select[name="slect_category"]')
            let subCategroy = $('select[name="slect_sub_category"]')
            categroy.on('change',function(){
                let id = $(this).val()
                let url = `{{ route('ajax.product', ':id') }}`
                let newurl = url.replace(':id', id);
                $.ajax({
                    url: newurl,
                    dataType: 'json',
                    type: "get",
                    success: function(response){
                        let options =[]
                        response.map(element =>{
                            console.log(element)
                            let option = `<option value="${element.id}">${element.name}</option>`;
                            options.push(option)
                        })
                        subCategroy.html('')
                        subCategroy.html(options)
                    },
                })
            })
        </script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: toggle bootstrap modal with jquery 
Javascript :: express get full url 
Javascript :: generate random numbers in js 
Javascript :: console.log formdata 
Javascript :: collision circle 
Javascript :: javascript set target blank 
Javascript :: jquery reset select2 
Javascript :: remove non prime numbers js 
Javascript :: Masonry js cdn 
Javascript :: strip html tags javascript 
Javascript :: get url without query string 
Javascript :: Code to Unsubscribe all youtube channels. 
Javascript :: how to check if input file is empty in jquery 
Javascript :: document ready 
Javascript :: xss test 
Javascript :: node js on ctrl c 
Javascript :: phone number regex angular 
Javascript :: javascript replace two spaces with one 
Javascript :: js get object by id from array 
Javascript :: regex for time in hh:mm:ss 
Javascript :: get sibling element after element 
Javascript :: jquery uncheck checkbox 
Javascript :: useeffect will unmount 
Javascript :: tailwind css calc 
Javascript :: javascript includes case insensitive 
Javascript :: htmlWebpackPlugin.options.title 
Javascript :: how to make javascript progarm that randomly displayes a word 
Javascript :: how to call action from another module vuex 
Javascript :: title case a sentence-javascript 
Javascript :: how to check connected devices in react native 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =