user2567674
user2567674

Reputation: 191

How to pass $("#MyInputTag").val to my Ajax call and keep that value for later use

How can I send $("#query").val()) using my Ajax function ?

If I put my Ajax call in my $(document).ready(function() , my code doesn't work anymore (the script doesn't start). => I can see the 'test123' string on my next page but , but if I type something in my "query" Input_Field, and then click on my link href (pointing to the same location) , the input field is reset and loose my value "query"... Please help me :( Thank you

$(document).ready(function() {

$("#completed").live('click', function() {
alert($("#query").val());

});

  $.ajax ({ 

url: 'http://localhost:3000/user/updateattribute',
data: { chosenformat: 'test123' , query: $("#query").val() } ,
type: 'POST',
success: function()
{
    alert ('success ' );
    return false;   }
});

});

Upvotes: 0

Views: 216

Answers (1)

alexmac
alexmac

Reputation: 239

// do not use this anymore $(document).ready(function() {

$(function() {
       event.preventDefault();
       // live is no longer used use on..
       $("#completed").on('click', function() {
       console.log($("#query").val()); 
       // alerts are annoying learn to use console  
});

Upvotes: 1

Related Questions