2014-04-29 94 views
0

我希望在Wordpress生成的页面上运行一些asp.net代码。有没有使用XMLHttpRequest()使JavaScript与.aspx页面交互就像Servlet一样的方法?如何使JavaScript与.aspx页面交互?

例如,我希望我能在JavaScript中做到这一点:

xmlHttpRequest.open("POST", "http ://some.aspx", true); 
send_request("request=add,1,2"); 
function getReadyStateHandler(xmlHttpRequest) { 
    //handle_response 
} 

如何编写和配置这样一个asp页面?有人知道一个很好的教程吗?

非常感谢!

+0

可能重复http://stackoverflow.com/questions/1102941/asp-net-ajax-examples - 对于最初级) –

回答

0

你最好在这个任务中使用JQuery。

Javascipt库有exactly functionality that you re looking for 您可以调用您的后端方法来调用将返回JSON object的serverside操作。然后在完成函数处理结果。

$.ajax({ 
    url: "test.html", 
    context: document.body 
}).done(function(result) { 
var dataFromTheSreverside = result; 
    $(this).addClass("done"); 
}); 

Here you可以找到很多的例子

的[对于初学者ASp.net Ajax的例子(