user3030342
user3030342

Reputation: 111

Jquery AJAX POST request issue in Classic ASP

I am using jQuery AJAX and following is my code:

$.ajax({
    type: "POST",         
    contentType: "multipart/form-data; charset=UTF-8",
    url: "../common/targetpage.asp",
    data: 'items=' + encodeURIComponent("123"),
    cache: false,        
    success: function (data) {
        if ($(data).find('couponDiscount').length > 0) {
            var couponDiscount = $(data).find('couponDiscount').text();
            return couponDiscount;
        }
        else {
            if ($(data).find('couponError').length > 0) {
                var couponError = $(data).find('couponError').text();
                alert(couponError);
                return 0;
            }
        }
    },
    error: function (result) {
        alert(result.responseText);
    }
});

When I use following line on target.asp page it gives nothing:

Response.Write(Trim(Request.Form("items")))
Response.End

But when I look into IE Developer tool: I Request Body Section I found "items=123" (without double quotes). I am not able to figure out the issue.

Upvotes: 0

Views: 1217

Answers (1)

Runcorn
Runcorn

Reputation: 5224

I think you have mistook-en the use of data in AJAX call. which normally is used as :

$.ajax({
    type: "POST",         
    contentType: "multipart/form-data; charset=UTF-8",
    url: "../common/targetpage.asp",
    data: {items : encodeURIComponent("123")},
    cache: false,        
    

You are sending a string instead of param to the POST call.

And from the jQuery documentation :

The data option can contain either a query string of the form key1=value1&key2=value2, or an object of the form {key1: 'value1', key2: 'value2'}.

Hope this helps your cause.

Upvotes: 1

Related Questions