title: Play 2.x: How to make an AJAX request with a common button
body: <p>So I have successfully gotten AJAX requests to work before but I have always had to use a form, and then at the end of the submit do return false so that it doesn't refresh the page.</p>
  <p>I have also just recently moved my JavaScript into a separate file this has caused my @ commands to fail. Because of this I do not no how to set my URL to my route?</p>
  <p>HTML:</p>
  <pre><code>&lt;button id=&quot;saveAsDefaultButton&quot;&gt;Save as default&lt;/button&gt;
  </code></pre>
  <p>Playframework Java code:</p>
  <pre><code>public static Result saveDefaultPhoneForUser(String handset) {
      User currentUser = User.findByName(session(&quot;name&quot;));
      currentUser.lastControlledHandset = theHandset;
      currentUser.save();
      return ok();
  }
  </code></pre>
  <p>routes:</p>
  <pre><code>POST    /                           controllers.Application.saveDefaultPhoneForUser(handset : String)
  </code></pre>
  <p>javascript:</p>
  <pre><code>$('#saveAsDefaultButton').click(function(evt) {
          $('#errors').hide();
          $.ajax({
              type : 'POST',
              url : &quot;controllers.Application.saveDefaultPhoneForUser&quot;,
              data : $('#controlledPhone option:selected').text(),
              dataType : &quot;text&quot;,
              success : function(data) {
                  //setError('Call succedded');
                  //$('#test1').attr(&quot;src&quot;, data)
              },
              error : function(data) {
                  setError('Make call failed');
              }
          });
          return false;
      });
  </code></pre>
  <p>I'm sure there is a way to do this but I am just having no luck finding anything.</p>