Page 1 of 1

Ajax request not working ?

Posted: Tue Mar 29, 2016 3:17 pm
by smallzoo
I have an ajax request which calls a php page(modadjustments.php) that inserts a record into a mysql table. If I run modadjustments with the correct query it works fine and inserts three records. If I run it from the main php page using ajax.request it doesn't.. any clues

main function

Code: Select all

function modifyAdjustments() {
		var formData = jQuery('#modadjustments').serialize();
                alert(formData);
               // this is =  "defid%5B1%5D=5&defid%5B2%5D=6&defid%5B3%5D=8"

		new Ajax.Request("/views/releases/modadjustments.php", { method:'post',
			    data: formData,
			    async:true,
				onSuccess: function(msg) {
					jQuery('#edit_adjustnments_div').dialog('close');				
			  	},
			  	onFailure: function(msg) {
				}		  
			});			    
		}


mod adjustments.php is

Code: Select all


.....
$conn->query($sql="DELETE FROM modified_adjustments where default_id<>''");
if(isset($_GET['defid']))
{
    foreach($_GET['defid'] as $did)
    {
        $conn->query($sql="INSERT INTO modified_adjustments (default_id)
	   				  VALUES (:did)", $params=array(':did'=>$did))	;
    }
}
.....

so if I run

modadjustments.php?defid_1=5&defid_2=6&defid_3=8

This inserts 3 records---SUCCESS

but if I try the same from the main page it just closes the div and has done nothing

What am I doing wrong

Thanks

Re: Ajax request not working ?

Posted: Tue Mar 29, 2016 10:37 pm
by Christopher
Have you verified that the Ajax request is happening at all? Try it with your test data and see if it works.

And, you're using jQuery, shouldn't it be:

Code: Select all

		jQuery.ajax("/views/releases/modadjustments.php", {
				method:'post',
				data: formData,
				async:true,
				onSuccess: function(msg) {
					jQuery('#edit_adjustnments_div').dialog('close');				
			  	},
			  	onFailure: function(msg) {
				}		  
			});