I am using the ajax post method to send values from aspx to php.in that i am calling that ajax method a s function in the button click event after inserting the values in the db only i will call the script but when i click the second time only that script is calling how to fix it while clicking at at first time itself?and also this method is not working in the firefox but working in IE when clicking for the second time.
<script type="text/javascript" language="javascript">
function resetFields()
{
$(document).ready(function(){
$("#<%=this.btnAdd.ClientID %>").click(function() {
// we want to store the values from the form input box, then send via ajax below
var ddlCompany = $("#<%=this.ddlCompany.ClientID %>").attr('value');
var txtLocation = $("#<%=this.txtLocation.ClientID %>").attr('value');
var txtDept = $("#<%=this.txtDept.ClientID %>").attr('value');
var ddlIndustryType = $("#<%=this.ddlIndustryType.ClientID %>").attr('value');
var txtDesg = $("#<%=this.txtDesg.ClientID %>").attr('value');
var ddlFnalArea = $("#<%=this.ddlFnalArea.ClientID %>").attr('value');
var txtExperience = $("#<%=this.txtExperience.ClientID %>").attr('value');
var txtJobDesc = $("#<%=this.txtJobDesc.ClientID %>").attr('value');
var txtEducation = $("#<%=this.txtEducation.ClientID %>").attr('value');
var txtDesiredProfile = $("#<%=this.txtDesiredProfile.ClientID %>").attr('value');
var txtPositionWanted = $("#<%=this.txtPositionWanted.ClientID %>").attr('value');
var txtAddedBy = $("#<%=this.txtAddedBy.ClientID %>").attr('value');
var txtContactName = $("#<%=this.txtContactName.ClientID %>").attr('value');
var txtEmailid = $("#<%=this.txtEmailid.ClientID %>").attr('value');
var txtContactno = $("#<%=this.txtContactno.ClientID %>").attr('value');
$.ajax({
type: "POST",
url: "http://172.16.126.32/Riyas/marggroup.com/get-current-openings.php",
data: "ddlCompany=" + ddlCompany + "& txtLocation="+ txtLocation+"& txtDept="+ txtDept+"& ddlIndustryType="+ ddlIndustryType+"& txtDesg="+ txtDesg+"& ddlFnalArea=" + ddlFnalArea+"& txtExperience="+ txtExperience+"& txtJobDesc="+ txtJobDesc+"& txtEducation="+ txtEducation+"& txtDesiredProfile="+ txtDesiredProfile+"& txtPositionWanted="+ txtPositionWanted+"& txtAddedBy="+ txtAddedBy+"& txtContactName="+ txtContactName+"& txtEmailid="+ txtEmailid+"& txtContactno="+ txtContactno,
success: function(response){
$('div.success').html(response);
}
});
return false;
});
});
}
</script>
codebehind:
protected void btnAdd_Click(object sender, EventArgs e)
{
c.MyQuery("insert into tblHrims_currentOpeningsNew(nvrDesignation,nvrCompany,nvrExperience,nvrLocation,nvrEducation,nvrDepartment,nvrIndustryType,nvrFnalArea,nvrJobDesc,nvrDesiredProfile,nvrContactPerson," +
" nvrContactNumber,nvrEmailId,nvrWantedPositions,nvrAddedBy,dttAddedon) values('" + txtDesg.Text.Trim().Replace("'", "") + "','" + ddlCompany.SelectedItem.Text + "','" + txtExperience.Text + "','" + txtLocation.Text + "','" + txtEducation.Text + "'," +
" '" + txtDept.Text.Trim().Replace("'", "") + "','" + ddlIndustryType.SelectedItem.Text + "','" + ddlFnalArea.SelectedItem.Text + "','" + txtJobDesc.Text.Replace("'", "''") + "','" + txtDesiredProfile.Text.Replace("'", "") + "'," +
" '" + txtContactName.Text.Trim().Replace("'", "") + "','" + txtContactno.Text.Trim().Replace("'", "") + "','" + txtEmailid.Text.Trim().Replace("'", "") + "','" + txtPositionWanted.Text.Trim().Replace("'", "") + "'," +
" '" + txtAddedBy.Text.Trim().Replace("'", "") + "','" + c.GetValue("select getdate()") + "')");
string strID = c.GetValue("select max(intsno) from tblhrims_currentopeningsNew");
Page.ClientScript.RegisterStartupScript(this.GetType(), "reset", " resetFields();", true);
}
onevent handler injquery.live, bind and delegateare deprecated in jquery 1.7.attr('value')insteadval()will work.include
datatype = 'html'in ajax call to denote thatresponsewill be inhtml.Also you have kept
$(document).ready(function(){inside the functionresetFields. which is not needed.remove function
resetFieldscall frombuttonelement.Then try using below code, i hope it will help you
and