Jump to content

script flexibility


HaLo2FrEeEk

Recommended Posts

Is there any way to pass post variables to a Javascript without explicitly setting them as a parameter in the function name?  For example, in AJAX, if I wanted to pass different url's with different parameters (like, page1 would have user_id, and count passed to it; page2 would have just a url passed to it) without making the javascript function look like this:

 

function dosomething(url, param1, param2, param3) {

  // blah...

  }

 

Could I just make the Javascript get whatever is in the form, no matter what or how many things are in it?

 

Does this make sense?

Link to comment
https://forums.phpfreaks.com/topic/62137-script-flexibility/
Share on other sites

It's AJAX though, so I can't do that, I need to have different parameters passed to the javascript, the closest I've gotten is this:

 

function ajax(url, div_id, param1, param2, elementname, element) {
  var poststr = param1+((param2 == null || param2 == '') ? "" : "&"+param2)+((element == null || element == '') ? "" : "&"+elementname+"="+document.getElementById(element).value);
  //alert(poststr);
  obj = document.getElementById(div_id);
  loading();
  makePOSTRequest(url, poststr);
  }

 

But that has it's flaws.

Link to comment
https://forums.phpfreaks.com/topic/62137-script-flexibility/#findComment-310549
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.