如何动态修改$.post网址?

$.post是否可以镜像表单的action=''?

我不想做多个$.post函数,但是action=''会随着用户在表单中选择要提交的内容而改变。因此,如果URL随着 action =''的变化而动态变化,那么我只需要一个$.post函数。

$("#txtrform").submit(function(){

    $.post('{*ACTION*#txtrform}', $("#txtrform").serialize(), function(data) {
        $("#col3").load("/include/txtrpbox/feed.php");
        $('input#txtrinput').val('');
    });

    return false;       
});
$("#txtrform").submit(function(){

    $.post($(this).attr('action'), $(this).serialize(), function(data) {
      ...
    });

    return false;       
});

Factor it out into a variable

var Target;
$("#txtrform").submit(function(){

    $.post(Target, $(this).serialize(), function(data) {
        $("#col3").load('/include/txtrpbox/feed.php');
        $('input#txtrinput').val('');
    });

    return false;       
});

Target = '/include/1.php';

//submit now will go to 1.php

Target = '/include/2.php';
//submit now will go to 1.php