Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have a javascript function for calling the controller function 'GetTemp' as below
function test()
{
     var _TempIds = {};
    _TempIds["iHospitalId"] = "1";
    _TempIds["iClinicId"] = "2";
    _TempIds["iDoctorId"] = "3";

    $.ajax({
        type: "POST",
        url: "../Home/GetTemp",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: JSON.stringify(_TempIds), 
        error: function (xhr, statusText) {
            alert("Error while processing the request, please try again.");
        },
        success: function (result, textStatus) {
            if (textStatus == "success") {

                alert("succ");
            }
        }
    });
}


But, executing the error part in chrome.but it working fine in ie.getting error at

data: JSON.stringify(_TempIds). how to solve this?

Thanks..
Posted
Updated 12-Sep-13 4:22am
v2
Comments
What is that error? Can you see that in Console?

1 solution

If i understand your question right , you want to pass an array to your controller so you can do like this

JavaScript
<script>
var _TempIds = [];
    _TempIds["HospitalId"] = "1";
    _TempIds["ClinicId"] = "2";
    _TempIds["DoctorId"] = "3";


function fun()
{

$.ajax({
            type: "POST",
            cache: false,
            url: "/Controller/Action",
            dataType: "json",
            traditional: true,
            data: {
                _TempIds: _TempIds

            }
        });


}
</script>


and in your controller you can access your array like this

C#
public ActionResult Index(IEnumerable<string>_TempIds)
{
// use your logic here
return View();

}



<pre lang="text">I hope this will help you 
Cheers!!
 
Share this answer
 
v5

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