javascript Ajax through PassAjaxResponseToFunction

Kailash Singh
Kailash...
Participant
206 Points
23 Posts

Hello sir, Here is my code for PassAjaxResponseToFunction. Its not executing.. 

<script src="bootstrap-3.3.6-dist/js/salajax.js"></script>
<script type="text/javascript">
function CheckName(i) {
var name = i.value;

var Path = 'CommonAjax.aspx?CheckName=MyName&NameMethod="' + name + '"';
PassAjaxResponseToFunction(Path, ShowMyResult);

}
function ShowMyResult(args) {

alert(args);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div >
Name : <asp:TextBox ID="txtName" class="form-control" onblur="return CheckName(this);" runat="server"></asp:TextBox>
</div>

 Here is the function of return by ajax. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyFirstMVCApp
{
public partial class CommonAjax : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["CheckName"] == "MyName")
{
MyName();
}
}
public void MyName()
{

String Status="";
string Name = Request.QueryString["NameMethod"];
if (Name=="Kailash")
{
Status= "Kailash";
}
else
{
Status="";
}
Response.Clear();
Response.Write(Status);
Response.End();
}
}
Views: 8799
Total Answered: 2
Total Marked As Answer: 1
Posted On: 07-Jan-2016 10:36

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

Do not use double quotes in path use as:

var Path = 'CommonAjax.aspx?CheckName=MyName&NameMethod=' + name + '';
Posted On: 07-Jan-2016 21:37
indradaman sharma
indrada...
Participant
116 Points
14 Posts
         

your problem is in this line

var Path = 'CommonAjax.aspx?CheckName=MyName&NameMethod="' + name + '"';

us it like

var Path = 'CommonAjax.aspx?CheckName=MyName&NameMethod=' + name ;

Posted On: 16-Jan-2016 12:54
 Log In to Chat