1
var url="service/signProcess.aspx";

//sets the important hidden field of the form by which server decides what to send

$('#hdnReqType2').val('sign87162');

var data=$("#frmLogin").serializeArray();
var success=function(rdata, textStatus, jqXHR) {
            console.log(rdata);
         };

var fail=function(jqXHR, textStatus, errorThrown) {
         console.log("Error" + errorThrown + "  " + textStatus);
     }
$.post(url,data,success,"text").fail(fail);

I am using this in the console of the page 'http://fsa.citop.in/lnct/' opened in chrome(when login form of the page is empty) and got a JSON String as response.

I found out at https://api.jquery.com/serializeArray/ that serializeArray() returns an array of objects having name and value. so when I used

var data=[{name :"txtLogId",value: ""},{name:"txtLogPass",value: ""},{name:"hdnReqType2",value: "sign87162"}];

which I thought to be equivalent object to object returned by $("#frmLogin").serializeArray() . Server gave me a HTML page in response.

I tried console.log(data) with both the version of data variable and couldn't find any difference. Please explain me whats the difference between both the version of data and what could be the correct equivalent object to serailizeArray().

Himanshu Singh
  • 228
  • 1
  • 3
  • 11
  • with which data did you compare the result of **$('#frmLogin').serializeArray()** – wrufesh Apr 24 '16 at 07:28
  • when did you make a **request** to server to get an **response**. – wrufesh Apr 24 '16 at 07:33
  • I compared $('#frmLogin').serializeArray() with [{name :"txtLogId",value: ""},{name:"txtLogPass",value: ""},{name:"hdnReqType2",value: "sign87162"}]. – Himanshu Singh Apr 24 '16 at 13:23
  • last line of the code $.post(url,data,success,"text").fail(fail); , I believe to be a post request – Himanshu Singh Apr 24 '16 at 13:24
  • the **data** in **success** callback function is the response object **(JSON)**. You can use any other name than **data**, and you will get it. – wrufesh Apr 24 '16 at 17:37
  • yeah. sorry for that. but I was talking about the data which is being send in the request. now I have corrected my question again. – Himanshu Singh Apr 25 '16 at 16:38

1 Answers1

0

The data argument in success callback is the response object (JSON). Your data variable before success function is conflicting with data argument in success callback. I suggest you change the name of the data variable or change the name of data argument in success function.

var url="service/signProcess.aspx";

//sets the important hidden field of the form by which server decides what to send

$('#hdnReqType2').val('sign87162');

var data=$("#frmLogin").serializeArray();
var success=function(dat_a, textStatus, jqXHR) {
        console.log(dat_a);
};

var fail=function(jqXHR, textStatus, errorThrown) {
         console.log("Error" + errorThrown + "  " + textStatus);
};
$.post(url,data,success,"text").fail(fail);

Here in the above code I have changed data argument in success callback function to dat_a.

wrufesh
  • 1,379
  • 3
  • 18
  • 36
  • yeah. sorry for that. but I was talking about the data which is being send in the request. now I have corrected my question again. – Himanshu Singh Apr 25 '16 at 16:37