0

Used one hidden element to capture changed value

and change the element value using jquery

changeValue(no){
   $('#mobileno').val(no);
}

and then pass the value to ajax

$.ajax({
    url:url,
    type: 'post',       
    data: '{"id":"1", "mobileno":$("#mobileno").val()}',
    success: function(data, status) {
    console.log("Success!!");        
    },    
});

mobileno field always shows empty value value while posting, if i am used alert in change value method then it is working fine

changeValue(no){
 $('#mobileno').val(no);    
 alert( $('#mobileno').val());
}

then it is working fine, your help will be appreciated

0

4 Answers 4

4

You've quoted your JS object making it into a string

$.ajax({
    url:url,
    type: 'post',       
    data: '{"id":"1", "mobileno":$("#mobileno").val()}',
    ------^                                            ^--------
    success: function(data, status) {
    console.log("Success!!");        
    },    
});

Use this

$.ajax({
    url:url,
    type: 'post',       
    data: {"id":"1", "mobileno": $("#mobileno").val() },
    success: function(data, status) {
    console.log("Success!!");        
    }    
});
Sign up to request clarification or add additional context in comments.

3 Comments

and perhaps removing the comma for the end of the .ajax() method parameters ?
@ManseUK that shouldn't affect any of the newer browsers, but good point. Updated.
This is always the first thing i check - ive been bitten by IE many times !
1

You shouldn't use single quots when assigning value to data parameter. Try this;

$.ajax({
    url:url,
    type: 'post',       
    data: {"id":"1", "mobileno":$("#mobileno").val()},
    success: function(data, status) {
    console.log("Success!!");        
    }
});

By the way, there is a trailing comma after success parameter which might cause problems.

Comments

1

Change your ajax call to :

$.ajax({
    url:url,
    type: 'post',       
    data: {"id":"1", "mobileno":$("#mobileno").val()}, //this line changed
    success: function(data, status) {
    console.log("Success!!");        
    }   // removed comma
}); 

Remove the quotes on the data line and the comma from the last bracket

Comments

1

Try:

$.ajax({
    url:url,
    type: 'post',       
    data: "id=1&mobileno="+$("#mobileno").val(),
    success: function(data, status) {
    console.log("Success!!");        
    },    
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.