开发者

ajaxSubmit does not reload page after first request (in CakePHP)

I'm creating a CMS which has a page edit section. I'm trying to create a Preview function. It works fine on the first attempt, but if you then change some text and preview again, the preview is the old version. It also appears very quickly. It's as if the ajaxSubmit function doesn't bother reloading the page.

I tried to get round this by changing the url each time (by adding on a timestamp to the end), but this made no difference. I'm using jquery, cakePHP and fck editor.

Here's what I have:

<script type="text/javascript">
$('#page_modal').jqm();
$('#preview_btn').click(function(e){
  // Get current page co开发者_JS百科ntent from fck iframe
  var oEditor = FCKeditorAPI.GetInstance('PageContent');
  var newcontent = oEditor.GetData();
  $('#PageContent').html(newcontent);

  // Submit form via Ajax
  var d=new Date();
  var t=d.getTime();
  var thisurl = '/admin/pages/preview/' + t.toString();

  $('#ajaxForm').ajaxSubmit({
   url: thisurl,
   error: function(XMLHttpRequest, textStatus, errorThrown){                      
    alert(textStatus);
   },
   success: function(responseText){
    $('#page_modal').jqmShow().find('#page_modal_content').html(responseText);
   }
  });
  e.preventDefault(); 
 });
</script>

As I said, it works fine first time, but then on subsequent calls the content is not updated. Can anyone suggest anything?


Try marking the view (/admin/pages/preview) with no cache. In the actual view put:

<cake:nocache>

 // your view content here

</cake:nocache>

It may be that the view is being cached by cake so it does not update with subsequent calls.

http://book.cakephp.org/view/347/Marking-Non-Cached-Content-in-Views

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜