Need help: None of my OnSuccess functions are workinghttp://forums.asp.net/t/1685313.aspx/1?Need+help+None+of+my+OnSuccess+functions+are+workingMon, 30 May 2011 20:33:32 -040016853134438135http://forums.asp.net/p/1685313/4438135.aspx/1?Need+help+None+of+my+OnSuccess+functions+are+workingNeed help: None of my OnSuccess functions are working <p>Looks like none of my jQuery functions that I call from OnSuccess in my AjaxOptions are firing up.</p> <p>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.</p> <p>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> <p>What am I doing wrong?</p> <p>Here's the full code of my partial view:</p> <p>&nbsp;</p> <pre class="prettyprint">@model MyModels.Companies.CompanyTwitterInfo &lt;h6&gt;Twitter Handle&lt;/h6&gt; &lt;div id=&quot;divTwitterForm&quot;&gt; @using (Ajax.BeginForm(&quot;EditTwitterInfoForSpecifiedCompany&quot;, &quot;Companies&quot;, new AjaxOptions { HttpMethod = &quot;GET&quot;, InsertionMode = InsertionMode.Replace, UpdateTargetId = &quot;divTwitter&quot;, OnSuccess = &quot;displaySuccess&quot; })) { @Html.TextBoxFor(model =&gt; model.TwitterHandle) &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; class=&quot;button&quot; /&gt; @Html.HiddenFor(model =&gt; model.CompanyId) } &lt;/div&gt; &lt;script type=&quot;text/javascript&quot;&gt; function displaySuccess() { var successMessageUrl = '@Url.Content(&quot;~/Content/messages/success.htm&quot;)' $('#divTwitterForm').load(successMessageUrl); } function closeFancy() { $.fn.fancybox.close(); } &lt;/script&gt;</pre> <p>Any idea what the solution may be?</p> <p>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.</p> <p>&nbsp;</p> <p>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.</p> 2011-05-30T16:28:50-04:004438148http://forums.asp.net/p/1685313/4438148.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>If you put a simple alert('test') in the onsuccess callback method, does that show?</p> 2011-05-30T16:43:11-04:004438150http://forums.asp.net/p/1685313/4438150.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Yes, I actually just tried that and it worked.</p> 2011-05-30T16:44:16-04:004438156http://forums.asp.net/p/1685313/4438156.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Great, and if you alert or check the value of the html you are trying to load. Does that work?</p> 2011-05-30T16:46:37-04:004438157http://forums.asp.net/p/1685313/4438157.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Not sure what you mean by value of the html.</p> 2011-05-30T16:48:16-04:004438163http://forums.asp.net/p/1685313/4438163.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>You have a link to a html file. If you alert the value of the successMessageUrl and browse to that so the file &quot;works&quot;.</p> <p>&nbsp;</p> <p>Also, can you alert:</p> <p>&nbsp;</p> <p>alert(&#36;<span class="pun">(</span><span class="str">'#divTwitterForm'</span><span class="pun">)</span>) to see if that really is found by jquery</p> 2011-05-30T16:50:25-04:004438164http://forums.asp.net/p/1685313/4438164.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>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:</p> <p><pre class="prettyprint">@model MyModels.Companies.CompanyTwitterInfo &lt;h6&gt;Twitter Handle&lt;/h6&gt; &lt;div id=&quot;divTwitterForm&quot;&gt; @using (Ajax.BeginForm(&quot;EditTwitterInfoForSpecifiedCompany&quot;, &quot;Companies&quot;, new AjaxOptions { HttpMethod = &quot;GET&quot;, InsertionMode = InsertionMode.Replace, UpdateTargetId = &quot;divTwitter&quot;, OnSuccess = &quot;displaySuccess&quot; })) { @Html.TextBoxFor(model =&gt; model.TwitterHandle) &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; class=&quot;button&quot; /&gt; @Html.HiddenFor(model =&gt; model.CompanyId) } &lt;/div&gt; &lt;script type=&quot;text/javascript&quot;&gt; function displaySuccess() { var successMessageUrl = '&lt;div style=&quot;text-align: center;&quot;&gt;Thank you...&lt;/div&gt;'; $('#divTwitterForm').load(successMessageUrl); } function closeFancy() { $.fn.fancybox.close(); } &lt;/script&gt;</pre> </p> 2011-05-30T16:52:49-04:004438171http://forums.asp.net/p/1685313/4438171.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>So, try</p> <p>alert(&#36;('#divTwitterForm').html())</p> <p>and see what that displays</p> 2011-05-30T17:00:13-04:004438175http://forums.asp.net/p/1685313/4438175.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>It did NOT do anything. I also tried the code below and got no results:</p> <p>&nbsp;</p> <pre class="prettyprint">var successMessage = '&lt;div style=&quot;text-align: center;&quot;&gt;Thank you...&lt;/div&gt;'; $('#divTwitterForm').Html(successMessage);</pre> <p>I think this is further proof that it's not finding divTwitterForm, don't you think?</p> <p>&nbsp;</p> 2011-05-30T17:03:39-04:004438180http://forums.asp.net/p/1685313/4438180.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>This must have something to do with Ajax call.</p> 2011-05-30T17:05:26-04:004438183http://forums.asp.net/p/1685313/4438183.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>try wrapping the onsuccess in a jquery document.ready function</p> <p>&nbsp;</p> <p>&#36;(document).ready(function(){</p> <p>// your onsuccess method goes here...</p> <p>});</p> 2011-05-30T17:06:29-04:004438193http://forums.asp.net/p/1685313/4438193.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Did absolutely nothing!</p> <p>Here's what it looks like -- just in case I'm not doing it right. My JavaScript/jQuery skills are rudimentary at best.</p> <p><pre class="prettyprint">&lt;script type=&quot;text/javascript&quot;&gt; $(document).ready(function () { function displaySuccess() { var successMessage = '&lt;div style=&quot;text-align: center;&quot;&gt;Thank you...&lt;/div&gt;'; $('#divTwitterForm').Html(successMessage); //$('#divTwitterForm').load(successMessageUrl); } }); function closeFancy() { $.fn.fancybox.close(); } &lt;/script&gt;</pre> </p> 2011-05-30T17:13:16-04:004438204http://forums.asp.net/p/1685313/4438204.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Nothing I do is working. I even tried hiding the DIV with the form and showing a thank you DIV. Even that is NOT working! By the way, even the initial document.Ready() is not working. My divSuccess is showing at start up. If the document.Ready() was working, shouldn't it be hidden?</p> <p>&nbsp;</p> <pre class="prettyprint">@model MyModels.Companies.CompanyTwitterInfo &lt;h6&gt;Twitter Handle&lt;/h6&gt; @using (Ajax.BeginForm(&quot;EditTwitterInfoForSpecifiedCompany&quot;, &quot;Companies&quot;, new AjaxOptions { HttpMethod = &quot;GET&quot;, InsertionMode = InsertionMode.Replace, UpdateTargetId = &quot;divTwitter&quot;, OnSuccess = &quot;showMeSuccess&quot; })) { &lt;div id=&quot;divTwitterForm&quot;&gt; @Html.TextBoxFor(model =&gt; model.TwitterHandle) &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; class=&quot;button&quot; /&gt; @Html.HiddenFor(model =&gt; model.CompanyId) &lt;/div&gt; &lt;div id=&quot;divSuccess&quot;&gt; Thank you very much... &lt;/div&gt; } &lt;script type=&quot;text/javascript&quot;&gt; $(document).ready(function () { $('#divSuccess').Hide(); }); function showMeSuccess() { $('#divTwitterForm').Hide(); $('#divSuccess').Show(); } &lt;/script&gt;</pre> <p>&nbsp;</p> 2011-05-30T17:28:04-04:004438210http://forums.asp.net/p/1685313/4438210.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working Have you added the javascript in your master page/_Layout.cshtml file? 2011-05-30T17:34:45-04:004438216http://forums.asp.net/p/1685313/4438216.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Yes, all my references to jQuery and fancybox are in my _Layout.cshtml file.</p> <p>To make sure, I added them to my partial view as well. When I did, I wasn't able to open my modal dialog which I interpreted as a javascript conflict. When I removed it the references from the partial view, everything worked again -- except for the OnSuccess stuff.</p> 2011-05-30T17:37:50-04:004438219http://forums.asp.net/p/1685313/4438219.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Ok, can you try and move the success div outside the form? and not have the form inside the div as you had earlier? I think that can cause some problem</p> 2011-05-30T17:40:28-04:004438222http://forums.asp.net/p/1685313/4438222.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>I did. Same results.</p> <p>Do you think this is due to FancyBox? I really like FancyBox but do you think it's a better idea for me to use the jQuery-UI dialog?</p> 2011-05-30T17:44:32-04:004438224http://forums.asp.net/p/1685313/4438224.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Can you comment out all the fancybox stuff and see if that solves the problem? And yes, i think you should but still, it shouln't cause this problem</p> 2011-05-30T17:46:58-04:004438226http://forums.asp.net/p/1685313/4438226.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>If I comment out fancybox, then my partial view won't open in a modal dialog.</p> <p>How do I open a modal dialog using jQuery-UI? I already have all the references to it so just by calling it I should be able to open it -- just don't know how.</p> 2011-05-30T17:49:16-04:004438229http://forums.asp.net/p/1685313/4438229.aspx/1?Re+Need+help+None+of+my+OnSuccess+functions+are+workingRe: Need help: None of my OnSuccess functions are working <p>Get the fancybox back and change the call to Hide() to hide() with lower characters and see what happens :)</p> 2011-05-30T17:50:56-04:00