jQuery .load() function is hitting my <HttpPost()> action instead of my <HttpGet()>
I have an overloaded action in my method, one declared with and the other with .
I开发者_Go百科 use the Post metod to handle my form's submit button, which works fine.
I wanted the HttpGet method to handle a jQuery .load() action but that is instead also being caught by my Post method.
Any idea what I'm missing? Do I have to explicitl call a .get() or .ajax() to hit the right action?
Thanks!
-Ben
The .load
method could send an HTTP POST AJAX request as stated in the documentation:
The POST method is used if data is provided as an object; otherwise, GET is assumed.
For example
$('#result').load("/foo", { id: 123 }, function(result) {
});
will send a POST request.
If you want to be sure use $.get
, or $.ajax
with type: 'GET'
. Also don't forget that if you use GET request for AJAX some browsers might cache the results and get you into trouble or at least some weird behavior, so if you want fresh contents from your server use $.ajax
with cache: false
parameter.
精彩评论