0

Everything works fine when I run the method without including parameters, but when the method is run with parameters added, I get a 500 Internal Server Error. I am not sure what I am doing wrong, thanks for any help.

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Included below is the code that I am currently using:

  [WebMethod]
    public static string UploadNewImage(string filePath,string ImageTitle,string ImageDescription,string ImageKeywords)
    {
    }
var parameters = "{'filePath':'" + fileuploadpathValue.val() + "','ImageTitle':'" +
                titleValue.val() + "','ImageDescription':'" + descriptionValue.val() + "','ImageKeywords:'" +
                    keywordsValue.val() + "'}";
 $.ajax({
                type: "POST",
                url: "../MainService.asmx/UploadNewImage",
                contentType: "application/json; charset=utf-8",
                data: parameters,
                dataType: "json",
                success: AjaxSucceeded,
                error: AjaxFailed
            });
2
  • 1
    What do you have stored in parameters? Commented Aug 25, 2011 at 15:12
  • found the solution here stackoverflow.com/questions/5558217/…. Thanks for all the help. Commented Aug 25, 2011 at 16:26

2 Answers 2

1

change your parameters to as follows:

var parameters = {
filePath: fileuploadpathValue.val(),
ImageTitle:titleValue.val(),
ImageDescription:descriptionValue.val(),
ImageKeywords:keywordsValue.val()
};

or combine them as follows:

$.ajax({
                type: "POST",
                url: "../MainService.asmx/UploadNewImage",
                contentType: "application/json; charset=utf-8",
                data:  {
                    filePath: fileuploadpathValue.val(),
                     ImageTitle:titleValue.val(),
                     ImageDescription:descriptionValue.val(),
                     ImageKeywords:keywordsValue.val()
                     },
                dataType: "json",
                success: AjaxSucceeded,
                error: AjaxFailed
            });

also make sure that none of the val() here is null that is you dint have a value set on any of the above control if that is the csae you will get an error like "Null passed into parameter which does not accept null values"

Sign up to request clarification or add additional context in comments.

6 Comments

I tried that and it doesnt work. It says its a server side error. When I take the parameters out it works fine, but it breaks with the parameters in there.
@tsegay: I was concerned if jquery would encode the "" thinking its part of the string
@user516883, you can use firebug on Firefox to see where the server error is
really doesnt respond with no error. This is very weird, my code looks very simular to alot of examples, yet still nothing. Firefox just showed me the same thing chrome did. No specific error to go on.
please put in you server side code and also show us what values are being passed..
|
0

The problem is in your Json format,

This is working in my system,

 var parameters = '{"filePath": "'+fileuploadpathValue.val()+'","ImageTitle": "'+titleValue.val()+'","ImageDescription": "'+descriptionValue.val()+'","ImageKeywords": "'+keywordsValue.val()+'"}';
        $.ajax({
            type: "POST",
            url: "../MainService.asmx/UploadNewImage",
            contentType: "application/json; charset=utf-8",
            data: parameters,
            dataType: "json",
            success: AjaxSucceeded,
            error: AjaxFailed
        });
    });

Let me know if u need more in that

2 Comments

you dnt need to build up your json the way you have done.. jquery handles it for you...
@zzzz, what do you need to pass for jquery to build the json for you. Here I am trying to correct the syntax error in the question. Other wise u can pass the four parameters as it is.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.