I have a form with the field
<input type="hidden" name="user_id" id="user-id" value="">
I am setting the field value through javascript on button click(not form submission). I want to pass this value from javascript or from php to Controller. I searched for it and I found that ajax will be used for this. This is what I tried so far
$.ajax({
url: 'localhost:8000/test',
type: 'POST',
data: { id: 1 },
success: function()
{
alert("Settings has been updated successfully.");
}
});
I am beginner in Javascript and I have no idea about ajax too much. Please lead me in the right direction.(The above ajax is not working)
UPDATE
I get this error when I click the button
POST http://localhost:8000/test 500 (Internal Server Error)x.ajaxTransport.send @ jquery-1.10.2.min.js:6x.extend.ajax @ jquery-1.10.2.min.js:6openMessageBox @ js.js:28
and this is how I am calling the ajax request, openMessageBox on click of a button
function openMessageBox(){
$.ajax({ //line 28
url: 'test',
type: 'POST',
data: { id: $('#user-id').val() },
success: function()
{
alert("Settings has been updated successfully.");
}
});
}
id:1@Satpal