javascript - Issue using Ajax to add to database -


i tried posting flagged php i'm hoping time ajax or jquery more responses.

i've been having issue ajax add function week now. code using works in application no issues. i'm hoping can see if i've made mistakes or causing it. i've been able add items database via curl commands no issue isn't php code include 100% clarity. using slim framework

php code

$app->post('/additems/', 'additems'); function additems() {     $request = \slim\slim::getinstance()->request();     $q = json_decode($request->getbody());     $sql = "insert items(item1, item2, item3, item4, item5, item6, item7, item8, item9) values (:item1, :item2, :item3, :item4, :item5, :item6, :item7, :item8, :item9)";     try{         $db = getconnection();         $stmt=$db->prepare($sql);         $stmt->bindparam("item1", $q->item1);         $stmt->bindparam("item2", $q->item2);         $stmt->bindparam("item3", $q->item3);         $stmt->bindparam("item4", $q->item4);         $stmt->bindparam("item5", $q->item5);         $stmt->bindparam("item6", $q->item6);         $stmt->bindparam("item7", $q->item7);         $stmt->bindparam("item8", $q->item8);         $stmt->bindparam("item9", $q->item9);         $stmt->execute();         $db = null;     }     catch(pdoexception $e){         echo $e->getmessage();     } } 

ajax

$("#send").click(function(){     $.ajax({         type: 'post',         contenttype: "application/json",         data: addproject(),         url: rooturl + "/additems/",         datatype: "json",         success: function(data)         {             alert("data added");         },         error: function(data)         {             alert("error");         }     }); });  function addproject() {     return json.stringify({     "item1": item1,     "item2": item2,     "item3": item3,     "item4": item4,     "item5": item5,     "item6": item6,     "item7": item7,     "item8": item8,     "item9": item9,     }); } 

all item variables have strings assigned them

any appreciated.

mike

i taking wild guess here instead of using function addproject() return data in ajax request itself, can try calling before ajax call , save variable use variable instead of function itself.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -