ajax - $(document).ready doesn't work however page is loaded -
as can understand title, browser doesn't call getreleatedproducts
method. put breakpoint $(document).ready(function ()
line doesn't enter ajax call. checked have jquery reference. have idea?
$(document).ready(function () { $.ajax({ type: "post", url: "http://localhost:2782/ajaxcallpage.aspx/getreleatedproducts", data: "{productid:" + productid + "}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (data) {...}
you've told server you're sending json:
contenttype: "application/json; charset=utf-8",
...but you're sending it:
data: "{productid:" + productid + "}",
...is not valid json. valid json, key productid
must in double quotes:
data: '{"productid":' + productid + '}', // ^ ^
(here i'm assuming productid
number. if it's string, need in double quotes.)
so suspect server side rejecting call because json invalid.
it's bit unusual send json to server, although it's valid if server coded expect , if send correctly. it's more typical send data server using default application/x-www-form-urlencoded
.
so unless you've coded server side expect receive json, remove contenttype
option $.ajax
call , change data
to:
data: {productid: productid}
...which tells jquery encoding you.
Comments
Post a Comment