Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery Ajax post sometimes turns to get MVC
    text
    copied!<p>I have the following line in my page which is called whenever a change is made in the form (the change in the form is persisted and stored in session):</p> <pre><code>function persistFormDetails() { $.post("&lt;%= Url.Action&lt;AvailabilityController&gt;(action =&gt; action.PersistForm(null)) %&gt;", $("form#availabilityForm").serialize()); } </code></pre> <p>The above is called from 3 different events happening on the page: $("select").change, $("#NumberOfNights").change, $("#PromoCode").change.</p> <p>These are the only 3 calls to 'PersistForm'. This works most of the time, but >5% of the time, 'PersistForm' is called using get instead of post. Extract from our weblogs for a failed request:</p> <pre><code>2012-08-07 06:17:34 120.151.214.16 - HTTP 10.12.0.151 80 POST /availability/persistform - 302 1151 434 0 HTTP/1.1 Mozilla/5.0+(iPhone;+CPU+iPhone+OS+5_1_1+like+Mac+OS+X)+AppleWebKit/534.46+(KHTML,+like+Gecko)+Version/5.1+Mobile/9B206+Safari/7534.48.3 __utma=212581192.532115380.1343637559.1343637559.1344320319.2;+__utmb=212581192.1.10.1344320319;+__utmc=212581192;+__utmz=212581192.1343637559.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);+.BREAKFREEBOOKING=H7n50kf8yh2VLsbC2Czo6LALPpef1jqj4RtcC4l34Q-fA3WKG8dD5Dps9CFq2i3j-YEVMEH5qTh_b5f7IDRJ5NYeB28gBV_czMmGeSfnd26FHsw83WbwBpz2K3oAVYCg6dG_MiOKqrpn8ViaBizKMKXD4yw1;+stella_referrer=referrerGuestId=14076864270&amp;additionalInfo=mantra_on_kent_24h_sale30aug12&amp;referrerSite= http://m.mantra.com.au/check-availability 2012-08-07 06:17:34 120.151.214.16 - HTTP 10.12.0.152 80 GET /availability/persistform chkCookies=True 302 950 353 0 HTTP/1.1 Mozilla/5.0+(iPhone;+CPU+iPhone+OS+5_1_1+like+Mac+OS+X)+AppleWebKit/534.46+(KHTML,+like+Gecko)+Version/5.1+Mobile/9B206+Safari/7534.48.3 __utma=212581192.532115380.1343637559.1343637559.1344320319.2;+__utmb=212581192.2.10.1344320319;+__utmc=212581192;+__utmz=212581192.1343637559.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);+.testCookie=.testCookie;+.BREAKFREEBOOKING=H7n50kf8yh2VLsbC2Czo6LALPpef1jqj4RtcC4l34Q-fA3WKG8dD5Dps9CFq2i3j-YEVMEH5qTh_b5f7IDRJ5NYeB28gBV_czMmGeSfnd26FHsw83WbwBpz2K3oAVYCg6dG_MiOKqrpn8ViaBizKMKXD4yw1;+stella_referrer=referrerGuestId=14076864270&amp;additionalInfo=mantra_on_kent_24h_sale30aug12&amp;referrerSite= http://m.mantra.com.au/check-availability </code></pre> <p>Note the first call to 'PersistForm' does a post (correct) but then 302's (not sure why its redirecting). Then the very next call from the same user on the same session and time calls 'PersistForm' and this time its with get. Then we get an exception "A public action method 'persistform' was not found on controller 'MG.Mobile.Controllers.AvailabilityController'".</p> <p>This makes sense as my 'PersistForm' action has a HttpPost attribute.</p> <pre><code>[HttpPost] public ActionResult PersistForm(AvailabilityForm form) { var model = _availabilityMapper.MapViewToDomain(form); _availabilitySession.SaveAvailabilityToSession(model); return new EmptyResult(); } </code></pre> <p>We can't allow gets on this action as it posts a lot of data. As I said earlier, this only happens about 5% of the time (maybe less).</p> <p>Any ideas on why I sometimes get a 'get' instead of a 'post' or why the call to 'persistform' 302's (redirects) sometimes?</p> <p>This is for our mobile site and the problem has only shown up with iPhone (but this could just be coincidence as 75% of mobile visits to our site are with iPhone).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload