使用javascript调用服务器端代码后无法刷新页面 [英] Cannot refresh the page after calling Server Side code using javascript

查看:62
本文介绍了使用javascript调用服务器端代码后无法刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ajax的EnablePageMethods方法来使用javascript调用服务器端代码.问题是在IE8中,ajax调用完成后,即服务器端功能已成功执行后,页面会自动刷新.我希望Chrome和Firefox也会发生同样的情况,但是一旦执行服务器端功能,它就不会刷新页面.

I am using Ajax's EnablePageMethods way to call server side code using javascript. The problem is that in IE8 the page automatically refreshes after the ajax call has been completed i.e. the server side function has been executed successfully. I want the same to happen with Chrome and Firefox but it doesnt refresh the page once the server side function has been executed.

任何想法或建议如何实现?

Any idea or suggestion how to achieve that?

我正在使用这种方式从Javascript调用服务器端代码- http://www.codeproject.com/KB/ajax/Ajax_Call_using_AjaxNet.aspx

I am using this way to call server side code from Javascript -- http://www.codeproject.com/KB/ajax/Ajax_Call_using_AjaxNet.aspx

这是javascript函数:

this is the javascript function:

   function editNode(note) {              
   PageMethods.deleteNote(note);                  
    } 

这是服务器端功能:

[System.Web.Services.WebMethod]
public static void deleteNote(int noteId)
{
string test = noteId.ToString();
Note note = new Note(noteId);
note.IsDeleted = true;
note.update();
}

这是我调用javascript事件的地方:

this is where i am calling the javascript event:

<a href='myPageName.aspx' onclick='javascript:editNode(1);return false;'>Delete</a>

推荐答案

这是我的操作方式:

     function editNode(note) {              
              PageMethods.deleteNote(note,OnSuccess,OnFailure);  

                 } 
        function OnSuccess() {         
        if (!navigator.appName == 'Microsoft Internet Explorer')
             {
             window.location.href=window.location.href;
             }             
           }
        function OnFailure(error) {             
            }     

我在此链接上找到了此解决方案:

I found this solution on this link:

http://www.codedigest.com/CodeDigest/80-Calling-a-Serverside-Method-from-JavaScript-in-ASP-Net-AJAX---PageMethods.aspx

这篇关于使用javascript调用服务器端代码后无法刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆