Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Last active March 23, 2016 20:51
Show Gist options
  • Select an option

  • Save cheeyeo/16e25b6212cae05a7911 to your computer and use it in GitHub Desktop.

Select an option

Save cheeyeo/16e25b6212cae05a7911 to your computer and use it in GitHub Desktop.
Jquery + Ajax If-Modified-Since
@cheeyeo
Copy link
Copy Markdown
Author

cheeyeo commented Mar 23, 2016

$.ajax( {
    type : 'GET',
    url : 'list.php',
    dataType: 'json',
    data : {
        pref : $('#pref').val(),
        type : $('#type').val()
    },
    beforeSend : function( xhr ){
        xhr.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
    },
    success : function(data) {
        $('#list').empty();
        options = new Array();

        $.each(data, function(i, v){
            options.push('<option value="' + i + '">' + v + '</option>');
        });
        $('#list').append(options.join());
    },
    error : function(msg) {
       ....
    },
    complete : function(msg) {
       ....
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment