Ajax structure
I have this part of code, ajax will call a function saveContact with parameters name, phone, email, address, is this code ok?
$.ajax({
url: 'addressbook.php',
data: 'action=saveContact()','&name='+name+'&phone='+phone+'&email='+email+'&adresa='+adresa;
dataType: 'json',
type: 'post'
Related Article: Ajax saving post data?
is a JavaScript / DHTML / AJAX discussion thread by dyingatmidnight that has 2 replies and was last updated 8 months ago.
pucivogel
Junior Poster in Training
64 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
I did like this
url: 'addressbook.php?action=add'
this is in the .js file
in the .php file i have
$action=$_POST['action']
and there are two possibilities add or delete, i do the add but it's not uploading in the db. No errors show.
pucivogel
Junior Poster in Training
64 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
The error i get is indefined index 'action' on addressbook.php, how can it be undefined?
this is my success function :
success: function (j) {
//show the notice
$('#notice').empty().html();
//empty the input fields
$('#names').val('');
$('#phone').val('');
$('#email').val('');
$('#adresa').val('');
//refresh the address list
displayAddressList(j.kontakte);
}
pucivogel
Junior Poster in Training
64 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
It worked!!! Finally it was stored in the db. I can't see the contacts list , this is the code in the .js file
function displayAddressList(items){
//empty the contacts lists
var list=$('#kontakte-lists');
//save a client copy of the items array for validation whenever its refreshed from server
addresslist=items;
//loop thru all the items and add to the list
var lh="";
for(var i=0;i<items.length; i++){
lh+="<li>"+items[i].names;
lh+=" [ "+items[i].phone+" ] ",
lh+=" [ "+items[i].email+" ] ",
lh+=" [ "+items[i].adresa+" ] ";
lh+='<a href="#delete-id" class="deletebtn" contactid="'+items[i].id+'"> delete contact </a>'
lh+="</li>";
}
list.html(lh);
//set the delete button event after every reload
setDeleteButtonEvents()
}
And this is the code in the html
<ul id="#kontakte-lists">
<li><a href="#delete-id" class="deletebtn" contactid='1'> delete contact </a></li>
<li> <a href="#delete-id" class="deletebtn" contactid='2'> delete contact</a></li>
<li><a href="#delete-id" class="deletebtn" contactid='3'> delete contact</a></li>
</ul>
Actually class and contactid appear underlined. Otherwise could you show me another way to display contacts i have in the db?Thanks in advance
pucivogel
Junior Poster in Training
64 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
mmmm i didn't get this very much, anyway thanks for everything
pucivogel
Junior Poster in Training
64 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 3 Months Ago by
AleMonteiro