jquery - POST a JSON data on a Server URL using Javascript - Stack Overflow

I have prepared a JSON data and I need to post it on the server so that a service can be called. URL to

I have prepared a JSON data and I need to post it on the server so that a service can be called. URL to the server is available and I am making an AJAX call for the same to POST the data.

But I dont know where to place the JSON string that is generated.

My Code is as Follows:

function postJSONData(JSONData, localMode)
        {
            var localJSONData = JSONData;
            var postMode = localMode;

             $.ajax({
                    type: 'POST',
                    url: '',
                    dataType: 'xml',
                    success: function(data){
                        alert("SECOND POST JSON DATA");
                    }   // Success Function
    }); // AJAX Call

            alert("POST JSON ------------> "+localJSONData +" "+postMode);
        }

I want to post JSON data to the server URL. any Parameters to be used?

Thanks, Ankit.

I have prepared a JSON data and I need to post it on the server so that a service can be called. URL to the server is available and I am making an AJAX call for the same to POST the data.

But I dont know where to place the JSON string that is generated.

My Code is as Follows:

function postJSONData(JSONData, localMode)
        {
            var localJSONData = JSONData;
            var postMode = localMode;

             $.ajax({
                    type: 'POST',
                    url: 'https://tt.s2./tmobile/subscribe-service/uid=ankit_bharat_tanna',
                    dataType: 'xml',
                    success: function(data){
                        alert("SECOND POST JSON DATA");
                    }   // Success Function
    }); // AJAX Call

            alert("POST JSON ------------> "+localJSONData +" "+postMode);
        }

I want to post JSON data to the server URL. any Parameters to be used?

Thanks, Ankit.

Share Improve this question edited Jan 9, 2013 at 7:37 Ankit Tanna asked Jan 9, 2013 at 7:35 Ankit TannaAnkit Tanna 1,8198 gold badges34 silver badges63 bronze badges 6
  • 1 data : { "requestParamName" : localJSONData } where "requestParamName" is whatever parameter name you are using in your server-side code to receive the JSON. – nnnnnn Commented Jan 9, 2013 at 7:39
  • Please visit the jQuery .ajax() doc and scroll down to read about the data setting. – PhearOfRayne Commented Jan 9, 2013 at 7:42
  • why dataType:'xml' you want to send it xml based or you want to access it? – Jai Commented Jan 9, 2013 at 7:44
  • I want to sent JSON data to the server. – Ankit Tanna Commented Jan 9, 2013 at 7:49
  • what is your variable localJSONData cantains , please show us – Kanishka Panamaldeniya Commented Jan 9, 2013 at 8:00
 |  Show 1 more ment

2 Answers 2

Reset to default 2

You should pass the values with data parameter $.ajax() jquery doc link

function postJSONData(JSONData, localMode)
    {
        var localJSONData = JSONData;
        var postMode = localMode;

         $.ajax({
                type: 'POST',
                url: 'https://tt.s2./tmobile/subscribe-service/uid=ankit_bharat_tanna',
                contentType:"application/json; charset=utf-8",
                dataType:"json"
                data:  JSONData
                success: function(data){
                    alert("SECOND POST JSON DATA");
                }   // Success Function
}); // AJAX Call

        alert("POST JSON ------------> "+localJSONData +" "+postMode);
    }

You are missing the data parameter. Moreover you need to send json data so dataType parameter should be set to json. Below is an Example

function postJSONData(JSONData, localMode)
        {
            var localJSONData = JSONData;
            var postMode = localMode;

             $.ajax({
                    data: localJSONData,
                    type: 'POST',
                    url: 'https://tt.s2./tmobile/subscribe-service/uid=ankit_bharat_tanna',
                    dataType: 'json',
                    success: function(data){
                        alert("SECOND POST JSON DATA");
                    }   // Success Function
    }); // AJAX Call

            alert("POST JSON ------------> "+localJSONData +" "+postMode);
        }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742392465a4435285.html

相关推荐

  • jquery - POST a JSON data on a Server URL using Javascript - Stack Overflow

    I have prepared a JSON data and I need to post it on the server so that a service can be called. URL to

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信