Looks like none of my jQuery functions that I call from OnSuccess in my AjaxOptions are firing up.
All I'm trying to do is open up modal dialog which is a partial view, then let user enter some data via an Ajax call.
I first tried to close the modal which didn't work. Then I decided to load up some message into the modal using jQuery.load() and that's not working either. Looks like none of my jQuery calls are working.
P.S. the Ajax call is actually working i.e. it's submitting the data entered by the user into the database and refreshing the DIV in the parent view to show the newly entered data.
The closeFancy() function is another appraoch I tried which didn't work. The partial view that included in this post opens up in a fancybox modal dialog. My original idea was to close the modal OnSuccess. That didn't work either. That's why I'm thinking
none of the javascript functions I call OnSuccess are working.
Here's what I did. I provided what I want displayed in the DIV locally so that I don't have to worry about locating an HTML file and it did NOT work. That means, it's not locating the divTwitterForm. Here's the full partial view again:
SamU
Contributor
2895 Points
1627 Posts
Need help: None of my OnSuccess functions are working
May 30, 2011 04:28 PM|LINK
Looks like none of my jQuery functions that I call from OnSuccess in my AjaxOptions are firing up.
All I'm trying to do is open up modal dialog which is a partial view, then let user enter some data via an Ajax call.
I first tried to close the modal which didn't work. Then I decided to load up some message into the modal using jQuery.load() and that's not working either. Looks like none of my jQuery calls are working.
What am I doing wrong?
Here's the full code of my partial view:
@model MyModels.Companies.CompanyTwitterInfo <h6>Twitter Handle</h6> <div id="divTwitterForm"> @using (Ajax.BeginForm("EditTwitterInfoForSpecifiedCompany", "Companies", new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "divTwitter", OnSuccess = "displaySuccess" })) { @Html.TextBoxFor(model => model.TwitterHandle) <input type="submit" value="Submit" class="button" /> @Html.HiddenFor(model => model.CompanyId) } </div> <script type="text/javascript"> function displaySuccess() { var successMessageUrl = '@Url.Content("~/Content/messages/success.htm")' $('#divTwitterForm').load(successMessageUrl); } function closeFancy() { $.fn.fancybox.close(); } </script>Any idea what the solution may be?
P.S. the Ajax call is actually working i.e. it's submitting the data entered by the user into the database and refreshing the DIV in the parent view to show the newly entered data.
The closeFancy() function is another appraoch I tried which didn't work. The partial view that included in this post opens up in a fancybox modal dialog. My original idea was to close the modal OnSuccess. That didn't work either. That's why I'm thinking none of the javascript functions I call OnSuccess are working.
Sam
Knecke
Contributor
3712 Points
838 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 04:43 PM|LINK
If you put a simple alert('test') in the onsuccess callback method, does that show?
.NET Developer (ASP.NET, MVC, WPF) MCTS .NET 4 (Web, WCF)
Blog | Twitter
SamU
Contributor
2895 Points
1627 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 04:44 PM|LINK
Yes, I actually just tried that and it worked.
Sam
Knecke
Contributor
3712 Points
838 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 04:46 PM|LINK
Great, and if you alert or check the value of the html you are trying to load. Does that work?
.NET Developer (ASP.NET, MVC, WPF) MCTS .NET 4 (Web, WCF)
Blog | Twitter
SamU
Contributor
2895 Points
1627 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 04:48 PM|LINK
Not sure what you mean by value of the html.
Sam
Knecke
Contributor
3712 Points
838 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 04:50 PM|LINK
You have a link to a html file. If you alert the value of the successMessageUrl and browse to that so the file "works".
Also, can you alert:
alert($('#divTwitterForm')) to see if that really is found by jquery
.NET Developer (ASP.NET, MVC, WPF) MCTS .NET 4 (Web, WCF)
Blog | Twitter
SamU
Contributor
2895 Points
1627 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 04:52 PM|LINK
Here's what I did. I provided what I want displayed in the DIV locally so that I don't have to worry about locating an HTML file and it did NOT work. That means, it's not locating the divTwitterForm. Here's the full partial view again:
@model MyModels.Companies.CompanyTwitterInfo <h6>Twitter Handle</h6> <div id="divTwitterForm"> @using (Ajax.BeginForm("EditTwitterInfoForSpecifiedCompany", "Companies", new AjaxOptions { HttpMethod = "GET", InsertionMode = InsertionMode.Replace, UpdateTargetId = "divTwitter", OnSuccess = "displaySuccess" })) { @Html.TextBoxFor(model => model.TwitterHandle) <input type="submit" value="Submit" class="button" /> @Html.HiddenFor(model => model.CompanyId) } </div> <script type="text/javascript"> function displaySuccess() { var successMessageUrl = '<div style="text-align: center;">Thank you...</div>'; $('#divTwitterForm').load(successMessageUrl); } function closeFancy() { $.fn.fancybox.close(); } </script>Sam
Knecke
Contributor
3712 Points
838 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 05:00 PM|LINK
So, try
alert($('#divTwitterForm').html())
and see what that displays
.NET Developer (ASP.NET, MVC, WPF) MCTS .NET 4 (Web, WCF)
Blog | Twitter
SamU
Contributor
2895 Points
1627 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 05:03 PM|LINK
It did NOT do anything. I also tried the code below and got no results:
var successMessage = '<div style="text-align: center;">Thank you...</div>'; $('#divTwitterForm').Html(successMessage);I think this is further proof that it's not finding divTwitterForm, don't you think?
Sam
SamU
Contributor
2895 Points
1627 Posts
Re: Need help: None of my OnSuccess functions are working
May 30, 2011 05:05 PM|LINK
This must have something to do with Ajax call.
Sam