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
            });
user516883
  • 8,868
  • 23
  • 72
  • 114

2 Answers2

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"

Baz1nga
  • 15,485
  • 3
  • 35
  • 61
  • 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. – user516883 Aug 25 '11 at 15:28
  • @tsegay: I was concerned if jquery would encode the "" thinking its part of the string – Baz1nga Aug 25 '11 at 15:30
  • @user516883, you can use firebug on Firefox to see where the server error is – tkt986 Aug 25 '11 at 15:32
  • 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. – user516883 Aug 25 '11 at 15:38
  • please put in you server side code and also show us what values are being passed.. – Baz1nga Aug 25 '11 at 15:45
  • I agree on @zzzz concern, there is an error on using "'" and '"' , try my answer on this page. – tkt986 Aug 25 '11 at 16:03
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

tkt986
  • 1,081
  • 3
  • 17
  • 25
  • you dnt need to build up your json the way you have done.. jquery handles it for you... – Baz1nga Aug 25 '11 at 18:19
  • @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. – tkt986 Aug 25 '11 at 21:10