1

I am using the following code to call external web service using jquery. In Chrome, I am getting this '500 Internal Server Error' and in firefox, it shows '0'

I am unable to figure out the problem. Here is my complete code..

 <script type="text/javascript" src="js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jQuery/1.2.6/jQuery.min.js">   
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnCall").click(function (event) {
            $.ajax({
                type: "POST",
                url: "www.google.com",
                data: "{'ESS123', 'aaaaaa', '', '[email protected]', '23424234', '', 0, 100, 1000007, 1, '', 12, '','','', '2013', '', 1, 1000006, 1000033, 100, 1000012, 1000012, 1000001, 1000001, 100, 'caff4eb4fbd6273e37e8a325e19f0991'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    alert('s');
                },
                error: AjaxFailed
            });
        });
    });
    function AjaxSucceeded(result) {
        alert('s');
        //alert(result.d);
    }
    function AjaxFailed(result) {
        alert(result.status + ' ' + result.statusText);
    }  
</script>

<body>
 <input type="button" value="Submit" id="btnCall" />
</body>

1 Answer 1

2

There could be additional reasons, but your data argument does not contain valid JSON. Invalid input is a common reason for 500 Internal Server Errors.

See JSONLint:

Parse error on line 1:
{    'ESS123',    'aaaaa
-----^
Expecting 'STRING', '}'

(Hint, strings in JSON must be quoted with " characters, and, unlike arrays, objects require key:value pairs not a list of values).

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

9 Comments

Thanks for your quick response.. Is this the way to do this.. data: {CompanyName: "ESS123", name: "Akhtar", title: "",
No. Keys in JSON objects must be strings. (And I've no idea what data the web service is expecting for input)
In this thread answer, he mention the correct way stackoverflow.com/questions/230401/…
Btw server should answer with 400 Bad request in case of bad input better ^^
@moonwave99 — I think that is when the request does not conform to the HTTP spec. You can have invalid JSON in the body without violating HTTP. Either way, what a server should do isn't all that relevant to the problem when you're working on the client side!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.