jQuery Get Request on HTTP URL

前端 未结 4 1497
耶瑟儿~
耶瑟儿~ 2020-12-29 00:54

i\'ve recently tried to get some Response from an URL using jQuery. Therefore I copied a get request sample of jQuery API Get Request Tutorial into my project and tried to r

4条回答
  •  猫巷女王i
    2020-12-29 01:28

    I have provided an example scenario to help get you started:

    
    

    This is probably best to include inside of an external JS file:

    //Listen when a button, with a class of "myButton", is clicked
    //You can use any jQuery/JavaScript event that you'd like to trigger the call
    $('.myButton').click(function() {
    //Send the AJAX call to the server
      $.ajax({
      //The URL to process the request
        'url' : 'page.php',
      //The type of request, also known as the "method" in HTML forms
      //Can be 'GET' or 'POST'
        'type' : 'GET',
      //Any post-data/get-data parameters
      //This is optional
        'data' : {
          'paramater1' : 'value',
          'parameter2' : 'another value'
        },
      //The response from the server
        'success' : function(data) {
        //You can use any jQuery/JavaScript here!!!
          if (data == "success") {
            alert('request sent!');
          }
        }
      });
    });
    

提交回复
热议问题