我正在尝试从服务器端加载 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/