简体   繁体   中英

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.

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.

There are no error messages being returned. The Ajax call gets a http 200 success code. 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.

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

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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