0

I am trying to get my javascript to call some C# code that I have added to my Sharepoint site. Unfortunately every time it runs, I'm not getting the "Success" i had programmed in. Instead I get this:

image 1

My Javascript code:

function test() {     
             $.ajax({
             type: "POST",
             url: 'NewForm.aspx/doThis',
             data: "",
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             success: function (msg) {
                alert("Success");
             },
             error: function (XMLHttpRequest, textStatus, errorThrown) {
                 alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
             }
         });
     };

And My C# code:

    [WebMethod]                                
 public static void doThis()
{
  //Code
}

The code is not supposed to do anything yet, but print out success if it was able to get to the method.

  • Are you using Internet Explorer? Did you try using some other browser , did it give the same error ? – user17970 May 6 '15 at 22:13
  • Firefox I get the same Request and status but the Error is: SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data – Tom May 7 '15 at 13:19
  • Chrome I get: Unexpected Token < – Tom May 7 '15 at 13:21
  • are you using SP 2013 or SP2010 and using spservices(spservices.codeplex.com) or plain javascript – user17970 May 7 '15 at 16:38
  • I'm using Microsoft Sharepoint Online 2013 and using SPservices version 2014.02 – Tom May 7 '15 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.