locked
Passing multiple parameters to AJAX call RRS feed

  • Question

  • User-1347535413 posted

    I'm trying to pass two parameters to the url in my Ajax call and it's not working. What is wrong with my format?  Thank you

    function getData() 
                {
                return $.ajax({
                        url: "/Books/GetBookList/" + "<%=ca.ID%>" + "&<%=ca.Title%>",
                        type: "GET", 
                        dataType: "json",
                        success: ShowBooks,
                        error: function (jqXHR, textStatus, errorThrown) { 
                        }
                     });
                    }
    


    Wednesday, July 23, 2014 9:00 PM

Answers

  • User-760709272 posted

    View the source and your code will be something like

    url: "/Books/GetBookList/" + "123" + "&Hello World",

    That will call

    /Books/GetBookList/123&Hello World

    which isn't a proper url.  You need to give the correct parameter name for whatever "title" is in your GetBookList method and use "?" rather than "&".

    Also try this instead (assuming the param name is also called title)

    url: "/Books/GetBookList/<%=ca.ID%>?title=<%=Server.UrlEncode(ca.Title)%>",

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 23, 2014 9:06 PM

All replies

  • User-760709272 posted

    View the source and your code will be something like

    url: "/Books/GetBookList/" + "123" + "&Hello World",

    That will call

    /Books/GetBookList/123&Hello World

    which isn't a proper url.  You need to give the correct parameter name for whatever "title" is in your GetBookList method and use "?" rather than "&".

    Also try this instead (assuming the param name is also called title)

    url: "/Books/GetBookList/<%=ca.ID%>?title=<%=Server.UrlEncode(ca.Title)%>",

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 23, 2014 9:06 PM
  • User-1347535413 posted

    Thank you Aidy. 

    Wednesday, July 23, 2014 9:40 PM