0

my url is look like :

localhost:1336/PartPicker/Part/Mobile/list_view

i want ajax post request. But ajax request is not wroking

my controller action code

 public JsonResult getProduct(String partid, String id)
    {
        return Json("success");
    }

my ajax request code

 function btn_Click()
    {
        var sdata = { partid: 'abc', id: 'xyz' };




        $.ajax({
            type: 'POST', 
            url: 'getProduct',
            data: JSON.stringify(sdata), 
            contentType: 'application/json;charset=utf-8', 
            dataType: "jsonp", 
            processdata: false, 
            success: function (data) { alert(data);},
            error: function (serverdata) { alert("eror " + serverdata.responseText) },
            async: false
        });


    }

route settings

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{partid}/{id}/",
            defaults: new
                        {
                            controller = "PartPicker",
                            action = "Part",
                            partid = UrlParameter.Optional,
                            id = UrlParameter.Optional
                        },

                          namespaces: new[] { " abc.Controllers" }

                        );

I can't identify why ajax request is not working. Please someone help me

7
  • What does "not working" mean? Are you getting a client side error? A server side error? You need to be specific when you ask, because "not working" can mean many different things. Commented Jul 7, 2014 at 20:23
  • i think there is no client side error. server not accepting the request. when url is look like localhost:1336/PartPicker/Part it works perfectly....@mason Commented Jul 7, 2014 at 20:34
  • "Server not accepting the request". What does that mean? Is there an error message? If so, post it in your question. You think there is no client side error? Use your browser's debugging tools to verify. Commented Jul 7, 2014 at 20:36
  • I think problem is in url. because when url is like localhost:1336/PartPicker/Part it works. but when url is look like localhost:1336/PartPicker/Part/Mobile/list_view then request fail Commented Jul 7, 2014 at 20:44
  • 1
    Yes, you said that already. Use your browser's debugging tools to see if the request fails. Also try navigating directly to localhost:1336/PartPicker/Part/Mobile/list_view and see what the response is. Commented Jul 7, 2014 at 20:45

1 Answer 1

1

Try this:

var sdata = "{'partid':'abc','id':'xyz'}";
Sign up to request clarification or add additional context in comments.

1 Comment

Could you elaborate on your answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.