Reputation: 128
Help! I'm getting a 500 internal server error when using the jquery ajax post method in our production environment. I've had this problem before and never was able to figure it out. At the time, I just decided to change the "POST" method to "GET"...and that worked. But now it's more critical that I'm able to use the jquery ajax post method. It's just a simple ajax post call but for some reason it blows up internally in the production environment.
It's a web farm using windows 2008 server with IIS7.
This is all I'm doing.
$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});
Upvotes: 0
Views: 18498
Reputation: 365
If you are calling a web method of server side, verify that the name of the argument is the same as the data declaration.
for ex:
[WebMethod()]
public static bool MyMethod(string myData)
{... }
client side:
$.ajax({
type: "POST",
contentType: "application/json",
data: "{'myData':'" + testVal + "'}",
url: "code.asmx/TestMethod",
beforeSend: function() {}
}).
Upvotes: 0
Reputation: 813
Is it just one piece of code you are having trouble with or "all" POST methods? Can you try the "test" template code below to verify if POST is working for even very basic server side methods. Your error is server side, so this is to verify that something will work server side at all. If this very basic code does not work, it can narrow down if it is your server side method that is the issue, or possibly the server configuration. I use code like this to verify I can POST at all before adding more complex methods. Also, use Fiddler to really see what is going on as it can give you much more detail about the error.
Wherever your server side code is:
[WebMethod]
public string TestMethod(string test)
{
return "I received the argument: " + test;
}
Your client side, using a newer version of JQuery:
<script>
$(function() {
var testVal = "this is a test string";
$.ajax({
type: "POST",
contentType: "application/json",
data: "{'test':'" + testVal + "'}",
url: "code.asmx/TestMethod",
beforeSend: function() {}
}).done(function(data) {
alert(data.d);
}).always(function() {
}).fail(function(jqXHR, textStatus, errorThrown) {
alert('Error: ' + errorThrown);
})
});
</script>
And possibly needed in your web.config
<configuration>
<system.web>
<webServices>
<protocols>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
Upvotes: 1
Reputation: 1941
EDIT: Pretty much useless unless you're on LAMP .. sorry bud
Usually apache stores the logs in /var/log/apache2/error_log.1 for the current day (could be missing the .1 just do a ls -l | head )
This is assuming you're on LAMP.
For SSL errors add ssl_
Upvotes: 2