访问var外部函数

I have the following code and I want to access id from the ajax function in the footer of the modal, is there anyway I can do it, i tried creating my own namespace or setting a variable outside the function

document.getElementById('editinputtext').style.height="200px";
document.getElementById('editinputtext').style.width="850px";   

             $.ajax({
                    type: "GET",
                    url : '/Proto/PHP/connect.php', 
                    datatype : 'json', 
                    success : function(data){
                    var obj = jQuery.parseJSON(data);
                         $(".contributions").click(function(){
                            var id = this.id // I need to save this var for later use!
                             document.getElementById("editinputtext").value =obj[id];


        });     
           }

             });


        </script> 
    </div>
    <div class="modal-footer">
      <button id="EDITcancel" type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      <button id="EDITsave" type="button" class="btn btn-default" data-dismiss="modal">Save</button>
      <script>
            $( "#EDITsave" ).click(function() {
             var a = id //I want to access the above id var here!!!
            $.ajax({
            type: "POST",
            datatype: "text",
            url: "/Proto/PHP/edit.php",
            data: {contribution_id: a+1, content: document.getElementById("editinputtext").value, storyID:1},
               });
                window.location.reload(false);
                });

  </script> 

You need to declare your var id in the outer-most scope to have it accessible in the later click-handler function:

var id;

$.ajax({
  type: "GET",
  url : '/Proto/PHP/connect.php', 
  datatype : 'json', 
  success : function(data){
  var obj = jQuery.parseJSON(data);
  $(".contributions").click(function(){
    id = this.id //same var id as declared above
    //etc...

<script>
  $( "#EDITsave" ).click(function() {
  var a = id //same var id as declared above

this _id var declaration should work for you:

// declare an upper variable
// to make it available for child scopes
var _id = null;

$.ajax({
  ...
  success: function(data) {
    var obj = jQuery.parseJSON(data);
    $(".contributions").click(function() {
      _id = this.id // save this var for later use!
      document.getElementById("editinputtext").value = obj[_id];
    });
  }

});


$("#EDITsave").click(function() {
  var a = _id // access the above id var here!!!
  ...
});

</div>