javascript - asp.net加载服务器端url但不打开页面或窗口

标签 javascript c# asp.net

我正在尝试从服务器端加载 URL,该 URL 是发送 SMS 的 API。

我的问题是我需要加载网址,但触发时不应打开页面或任何窗口。

string url = "http://xxxxx.xxxxx.com/api/sendmsg.php?user=xxxx&pass=xxxx&sender=xxx&phone=xxxxxxxxxxx&text=this%20is%20test%20sms&priority=ndnd&stype=normal";
string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);

最佳答案

好吧,您可以从客户端发送 ajax GET 请求,尽管我不明白为什么您不从服务器端调用此 URL。

这将是服务器端:

using(WebClient client = new WebClient ())
{
    string url = "http://xxxxx.xxxxx.com/api/sendmsg.php?user=xxxx&pass=xxxx&sender=xxx&phone=xxxxxxxxxxx&text=this%20is%20test%20sms&priority=ndnd&stype=normal";
    client.DownloadString(url);
}

如果您选择在客户端执行,则可以使用以下代码:

string url = "http://xxxxx.xxxxx.com/api/sendmsg.php?user=xxxx&pass=xxxx&sender=xxx&phone=xxxxxxxxxxx&text=this%20is%20test%20sms&priority=ndnd&stype=normal";
string s = "var xmlHttp = new XMLHttpRequest();";
s += "xmlHttp.open('GET'," + url + ", false);";
s += "xmlHttp.send(null);";

ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);

关于javascript - asp.net加载服务器端url但不打开页面或窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33872561/

相关文章:

c# - 如何删除字符串中的空格和换行符

javascript - 不评估模板内的变量

javascript - 使用 Javascript 将 PHP 变量转换为 HTML 文本框

c# - 为什么我的应用程序不会退出?

c# - 在 .NET 中转换 AVI 视频

c# - Controller 中的 Controller ?

asp.net - VB.Net 使用 System.Reflection 和 System.Type 初始化类以创建基于 session 的单例扩展方法

javascript - 将两个相交的数组合并成一个 HashMap,一个键和多个值

javascript - React Array Prop 在渲染时发生变化

c# - Cortana RequestDisambiguationAsync 错误