简体   繁体   English

jQuery ajax在我的C#代码中向Web方法发布查询,但无法实时运行,但可在localhost上运行

[英]jQuery ajax post query to a webmethod in my c# code behind not working live, but works on localhost

I'm using a fairly straightforward jQuery ajax post query to a webmethod in my c# code behind. 我正在后面的C#代码中使用相当简单的jQuery ajax后查询到Web方法。

This works great on my local machine, but when I moved it to the production server it stopped working. 这在我的本地计算机上效果很好,但是当我将其移至生产服务器时,它停止工作。

I opened the website on the production server in Visual Studio and when I run it from there it works fine, but if I open a browser on the production server and navigate to the URL of the page, then it doesn't work, though the code is obviously the same. 我在Visual Studio的生产服务器上打开了网站,然后从那里运行它时,它可以正常工作,但是如果我在生产服务器上打开浏览器并导航到页面的URL,则无法正常工作,尽管代码显然是相同的。

There are no error messages being returned. 没有错误消息被返回。 The Ajax call gets a http 200 success code. Ajax调用获得http 200成功代码。 The only difference is that when it is working, the response object is just the desired html string, whereas when it fails, the whole page content is being returned. 唯一的区别是,当它工作时,响应对象就是所需的html字符串,而当它失败时,将返回整个页面内容。

I have seen other threads with the same issue, however none of their fixes has worked on this project, I have uploaded the sample project below: 我看到了其他具有相同问题的线程,但是它们的修复都不适用于该项目,我在下面上传了示例项目:

http://stackoverflowexample1.ultrait.net/mapsearch.aspx http://stackoverflowexample1.ultrait.net/mapsearch.aspx

I think the issue you face is the protocol, check and compare your ajax and your production server HTTP URL, do they have the same protocol ie (HTTP or HTTPS), if NO then that is where the issue is coming from. 我认为您面临的问题是协议,请检查并比较您的ajax和生产服务器的HTTP URL,它们是否具有相同的协议(例如,HTTP或HTTPS),如果否,那么这就是问题所在。 The host server protocol must match with whatever request your app might be sending to avoid mixed content conflict.Any page using an HTTPS address must have all of the content within coming from a secured source. 主机服务器协议必须与您的应用程序可能发送的任何请求相匹配,以避免混合内容冲突。任何使用HTTPS地址的页面都必须包含来自安全来源的所有内容。

Example: Ajax Request

$.post("https://sample.com/demo_test_post.asp/myMethod",
{
    name: "Donald Duck",
    city: "Duckburg"
},
function(data, status){
    alert("Data: " + data + "\nStatus: " + status);
});

host URL must be https:// too and if you have http same thing goes there too this is what i think you're trying to solve, i hope my solution helps 主机URL也必须为https://,如果您也有http链接,这也是我认为您要解决的问题,希望我的解决方案有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM