Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to call a function of an AJAX post. The function can not be called I think to the tag on the function.

HomeController.cs
SQL
[???]
public JsonResult somefunction(string value)
{
     return Json(somelist2, JsonRequestBehavior.AllowGet);
}

Index.cshtml
XML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        ...
            $.post("Home/somefunction", json1, function (data,status) {
                alert(status)

                ...
                }

            }, "json")
        });
Posted
Comments
ZurdoDev 16-Feb-15 13:48pm    
I don't understand your question.
Kornfeld Eliyahu Peter 16-Feb-15 13:59pm    
And you are not alone...
Afzaal Ahmad Zeeshan 16-Feb-15 14:46pm    
Why don't you name the function, instead of creating this automatic function to be executed?

1 solution

When I used your code as is, it did not work. Once I add two semicolons it worked and invoked somefunction controller action. After alert(status) and after $.post() call semicolon was missing.
also json1 was not defined so I replaced it with {}
In Home Controller
------------------
SQL
public JsonResult somefunction(string value)
       {
           return Json("Text", JsonRequestBehavior.AllowGet);
       }



In Index View
-------------------

PHP
$(function () {

            $.post("Home/somefunction", {}, function (data, status) {
                alert(status);


            }, "json");
        });




Hope that helps,
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900