Jump to content

Multiple Post Requests?


jackpf

Recommended Posts

Hi all,

Just wondering if it's possible to send multiple post requests with ajax.

My current script is:

function AJAX(form, integer)
{
var message = 'post=whatever';

var url = '/main/misc.php?status=ajax';

if(window.XMLHttpRequest)
{
	var ajax = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
	var ajax = new ActiveXObject('Microsoft.XMLHTTP');
}
if(ajax)
{
	ajax.open('POST', url);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; Charset = UTF-8');

	ajax.send(message);
}
}

 

Now, I've tried stuff like

var message = 'post=whatever&post2=anotherpost';

But that doesn't seem to work.

Also tried

var message2 = 'post2=anotherpost';
ajax.send(message, message2);

 

Had a google as well and couldn't find anything.

 

Thanks in advance,

Jack.

Link to comment
Share on other sites

Hi jackpf , i would suggest that you use a library. it makes it really easy for you on that problem.

I personally use jquery of google.

 

here is an example on how to send to values(posts) into your server side script using ajax.

 


//this is to load the functions of jquery 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

//here is the script you have to write

<script type="text/javascript">
function act-deact()
{
  $('#id').load('act-deact.php',{ // ('#id') is the <div> or any other place you want to load the response. // 'act-deact.php' is the file that handles the values you send.
    'emp_id': $('#emp_id').val(), // emp_id is the 'id' of the <input type='' id='' /> you want to send
'do': $('#do').val()  // same as above
  });
}
</script>

I hope this helps.

If you need any more help just let me know

Link to comment
Share on other sites

Ahh, yeah, I prefer to code the stuff myself rather than use libraries tbh.

But I'd be surprised if jQuery can do this tbh.

Hmm...I've been trying to put the message into an array, and then send each message, but I can't get it to work...I'm not sure if this is actually possible.

Ahh well, thanks for your help.

Link to comment
Share on other sites

I don't think you have to use a content length header. Well...I never have and my ajax works.

For example, this would work (theoretically):

function AJAX(form, integer)
{
   var message = 'post=whatever';
   message += '&post2=something else'; // HERE IT ALLOWS ME TO ADD ANOTHER POST
   
   var url = '/main/misc.php?status=ajax';

   if(window.XMLHttpRequest)
   {
      var ajax = new XMLHttpRequest();
   }
   else if(window.ActiveXObject)
   {
      var ajax = new ActiveXObject('Microsoft.XMLHTTP');
   }
   if(ajax)
   {
      ajax.open('POST', url);
      ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; Charset = UTF-8');
      
      ajax.send(message);
   }
}

 

So yeah, if anyone is wondering how to do this, all you need to do is set it up like a query string.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.