This topic is locked
[SOLVED]

  Ajax call, multiple data

3/19/2012 3:53:40 PM
PHPRunner General questions
S
stiven author

Hello everyone,
I have a button on the edit page that when it is clicked it makes an ajax called to an external php page here is the code it works if i pass only one value but i need to pass two and im not sure how to fix this
this is the button

<input type="button" name="send_email" id=send_email value="Order Video" case_id="'.$values['case_no'].'" type="video" />


$("input[type='button'][name='send_email']").click(function(e){

$.ajax({

type: "POST",

url: "include/orders.php",

data: "case_id="+$(this).attr('case_id')+"type="+(this).attr('type'),//i added type here

success: function(msg){

alert("Order Sent.");

}



})

$(this).attr("disabled","disabeld");

$(this).attr("value","Order Sent");

});


this is the error

TypeError: Object #<HTMLInputElement> has no method 'attr'
Thanks

admin 3/19/2012

The following is wrong:

+(this).attr('type')


Should be this:

+$(this).attr('type')
S
stiven author 3/19/2012

Thanks so much! it worked!! but now i have another problem :/
on the php page im getting the values together and they should be separate :/ here is the code
ajax call



$("input[type='button'][name='send_email']").click(function(e){

$.ajax({

type: "POST",

url: "include/orders.php",

data: "case_id="+$(this).attr('case_id')+"order_type="+$(this).attr('order_type'),

success: function(msg){

alert("Order Sent.");

}



})

$(this).attr("disabled","disabeld");

$(this).attr("value","Order Sent");

});


php receiving page



$case_no = $_POST['case_id'];// this output 2012093order_type=flowers

$user = $_SESSION['UserID'];

$type = $_POST['order_type'];//this output nothing...
admin 3/20/2012

Sorry, not really a PHPRunner question. Check jQuery documentation and samples here:

http://api.jquery.com/jQuery.ajax/

S
stiven author 3/20/2012

Thanks I got it working I had to change the type to GET here is the result.


$("input[type='button'][name='send_email']").click(function(e){

$.ajax({

type: "GET",

url: "include/orders.php",

data: "case_id="+$(this).attr('case_id')+"&order_type="+$(this).attr('order_type'),

success: function(msg){

alert("Order Sent.");

}



})

$(this).attr("disabled","disabeld");

$(this).attr("value","Order Sent");

});