I'm using ajax for the first time and have hit a bit of a brick wall.
I've created a single big function with lots of smaller functions inside it which handles all ajax requests. I'm passing a POST variable to tell it which function to process the request with.
For example
if(_is_ajax()) {
if($_POST['save开发者_开发百科_company']) {
// Do stuff here
}
}
However, I don't know how to use jQuery ajax functions in a way where I can set the post variable AND pass serialized data.
here's my code:
var values = $("#edit_company").serialize();
$.post("/admin/companies", { 'save_company' : true } ,
function(data){
console.log(data);
}, "json")
'save_company' : true
sets the post variable, but where do I include values
?
You can try something similar to this:
var frm_data = $("#form1_id").serialize();
$.ajax(
{
type: "POST",
url: "url.php",
data: frm_data,
cache: false,
success: function(response)
{
alert(response);
}
});
$.post("/admin/companies", { 'save_company' : 'value1', var2: 'value2', var3: true }, callbackFcn);
Assuming that your form is #edit_company then:
$.post("/admin/companies", $("#edit_company").serialize() ,
function(data){
console.log(data);
}, "json");
Should send all the form data.
精彩评论