【问题标题】:Google App Engine with Ajax: Test the returned data使用 Ajax 的 Google App Engine:测试返回的数据
【发布时间】:2013-07-22 18:44:29
【问题描述】:

我曾经对 HTML 元素 <a class="getContent" href="/content">...</a> 使用以下 Ajax 代码:

$('.getContent').click(function() { 
  var url = $(this).attr('href'); 
  $('#content').load(url); 
  return false; 
});

如果我想根据服务器返回的值刷新整个页面:

$('.getContent').click(function() { 
  var url = $(this).attr('href');
  if (url == "success") {
    document.location.reload(true);
  }else{
    $('#content').load(url);
  }
  return false; 
});

当然,if 部分只是假设。由于我正在使用 python 开发 Google App Engine,服务器端脚本可能是:

if ...:
  self.response.out.write('success')
else:
  render(self, 'some_html_file.html')

我该怎么做?谢谢。

【问题讨论】:

    标签: ajax google-app-engine


    【解决方案1】:

    试试:

    var menuId = $("ul.nav").first().attr("id");
    var request = $.ajax({
      url: url, //your url here
      type: "POST",
      data: {id : menuId},
      dataType: "html"
    });
    
    request.done(function(msg) {
      $('#content').html( msg );
    });
    
    request.fail(function(jqXHR, textStatus) {
      //reload here
    });
    

    来源:http://api.jquery.com/jQuery.ajax/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      • 2015-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-12
      • 1970-01-01
      相关资源
      最近更新 更多