Opened 14 years ago

Closed 14 years ago

#125 closed defect (duplicate)

Could not insert custom parameters for Post methods while having form elements

Reported by: knave Owned by: anonymous
Priority: high Milestone:
Component: Core Version: 0.1
Keywords: ajax version Cc:
Blocked By: Blocking:

Description

dojo.io.bind is unable to mix both formNode and customised fields, as some occasions, it may be required.

e.g.

dojo.io.bind({
  url: "test.php",
  formNode: document.getElementById("frm"),
  method: "post",
  mimetype: "text/plain",
  load: function( type, data, evt ) {
    alert(data);
  },
  content:{
    TO_ADD : "yes",
    TO_TEST: "yes"
  }
});

Assumming the form has 2 hidden fields, it will submit as : MyField1=FIELD1Value&MyField2=FIELD2ValueTO_ADD=yes&TO_TEST=yes notice that the last element's value is concatenated with the custom content's first param's value.

should u use the following instead:

dojo.io.bind({
  url: "test.php",
  mimetype: "text/plain",
  load: function( type, data, evt ) {
    alert(data);
  },
  content:{
    TO_ADD : "yes",
    TO_TEST: "yes"
  }
});

, the output will be test.php?TO_ADD=yes&TO_TEST=yes& note that there is an extra "&" at the end.

Change History (2)

comment:1 Changed 14 years ago by knave

Solved!

IO.js

dojo.io.argsFromMap = function(map){
  var control = new Object();
  var mapStr = "";
  for(var x in map){
    if(!control[x]){
      if( mapStr.length>0 ) mapStr += "&"; //do check here
        mapStr+= encodeURIComponent(x)+"="+encodeURIComponent(map[x]); //removed the +"&"
    }
  }
  return mapStr;
}

BrowserIO.js Line 433. under this.bind function

	if(kwArgs["content"]){
	  if( query.length>0 ) query += "&"; //added the check			                
            query += dojo.io.argsFromMap(kwArgs.content);
	}

comment:2 Changed 14 years ago by david

Resolution: duplicate
Status: newclosed

Duplicate of 93, fixed. You can grab the latest nightly builds at http://archive.dojotoolkit.org.

Note: See TracTickets for help on using tickets.