Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
i have some functionality to pass id via json. but it returns below error

JSON.parse: unexpected end of data

i have no idea why not working on production server. works fine on my local mahchine. here is my code.


function AddSubscriptionToList(PublicationID, EmployeeID) {

        var pubid = { "PublicationID": PublicationID, "EmployeeID": EmployeeID };
        $.ajax({
            url: '@Url.Action("AddSubscriptionToDB", "Home")',
            cache: false,
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify(pubid),
            success: function (data) {
                //alert('added');
                loadPublicationList();
            }
        }).fail(
                 function (xhr, textStatus, err) {
                     alert(err);
                 });
    }
Posted
Updated 27-Mar-17 8:27am
v2
Comments
Ahmed Bensaid 27-Jan-14 10:37am    
What is the response of your ajax call ? (Chrome Console)

Should be more like this
function AddSubscriptionToList(PublicationID, EmployeeID) {
 
	var pubid = { "PublicationID": PublicationID, "EmployeeID": EmployeeID };
        $.ajax({
            url: '@Url.Action("AddSubscriptionToDB", "Home")',
            cache: false,
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify(pubid),
	    error: function (xhr, status, error) {
		alert(xhr.responseText);
	    },
            success: function (data) {
                //alert('added');
                loadPublicationList();
            }		
        });                 
    }
 
Share this answer
 
if Js file is not minify , Can you set a break point and check what is the value of pubid enabling debug on console. you can easily identify.
 
Share this answer
 
Comments
[no name] 27-Mar-17 14:37pm    
Your solution is for the OP to jump back in time THREE years and debug his code?
Chaminda Jayanath Udawatte 27-Mar-17 14:40pm    
Oh I am sory about it, i missed the dates

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