Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

Call external web service using jquery

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>

Upvotes: 1

Views: 1836

Answers (1)

Quentin
Quentin

Reputation: 943649

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).

Upvotes: 2

Related Questions