Search code examples
jqueryajaxblackberryxmlhttprequest

jQuery AJAX dataparam passing issue in Blackberry


I am using jquery ajax post method to submit form parameters to JAXRS service.

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "http://xyz.in/webservice.asmx/backup_p",
    data: "{ 'id': '1', 'data': '4' }",

    dataType: "json",
    success: function (msg) {
        alert('sucess !!!');
        alert(msg.d);


    },
    error: function (jqXHR, textStatus, errorThrown) {
        alert('hello');

        alert(jqXHR + " : " + textStatus + " : " + errorThrown);
    }
});

Before submitting input values as dataParam i am converting to JSON format. It is working in all devices except blackberry. In blackberry devices, request parameters are sending as null. I am not able to get any request parameter value in JAXRS resource layer. What is the rootcause of the issue?


Solution

  • I found out the rootcause of the issue. By default all browsers convert JSON object to serialized representation before submitting XMLHTTPREQUEST. But it is failing only in blackberry devices. So before submitting jQueryAJAX post method, dataParam needs to be converted as URLString by using $.param method.

    var fomrValues = $("form[name=" + N + "]").find("input").not('[value=""]');
    dataArray = formValues.serializeArrayDataAttr();
    dataParam = $.param(dataArray);
    

    This dataParam value needs to be passed in AJAX Post method.