Start New Discussion within our Web Development Community

I have this part of code, ajax will call a function saveContact with parameters name, phone, email, address, is this code ok?

 url: 'addressbook.php', 
 data: 'action=saveContact()','&name='+name+'&phone='+phone+'&email='+email+'&adresa='+adresa; 
 dataType: 'json', 
 type: 'post'

I don't think so. It should be like this:

     url: 'addressbook.php?action=saveContact', 
     data: {
        name: name,
        phone: phone,
        email: email,
        adresa: adresa
    dataType: 'json', 
    type: 'post'

I did like this

url: 'addressbook.php?action=add'   

this is in the .js file
in the .php file i have


and there are two possibilities add or delete, i do the add but it's not uploading in the db. No errors show.

Check the response using the success event. Like this:

sucess: function(data, textStatus) {


You should use your browser JS debugger and Networking monitoring to identify the errors.

You should also certify that your PHP configuration is set to show all the errors.

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   
//empty the input fields 
//refresh the address list 

Try like this:

     url: 'addressbook.php', 
     data: {
        action: 'add',
        name: name,
        phone: phone,
        email: email,
        adresa: adresa
    dataType: 'json', 
    type: 'post'

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 
//loop thru all the items and add to the list 
var lh=""; 
for(var i=0;i<items.length; i++){ 
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>' 
//set the delete button event after every reload 

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> 

Actually class and contactid appear underlined. Otherwise could you show me another way to display contacts i have in the db?Thanks in advance

I'd use something like this:

var lis = [];

for(var i=0, il=items.length,item; i<il, item=items[i]; i=i+1){ 
        '<li> ' +
            '{0} [ {1} ] [ {2} ] [ {3} ] ' +
            '<a href="void(0);" class="deletebtn" contactid="{4}"> delete contact </a>' +
        , item.names,,, item.adresa,


The String.format method is this one:

// --------------------------------------
// String.format
// --------------------------------------

String.prototype.format = function () {
    return String.format(this, arguments.length == 1 ? arguments[0] : arguments);

String.format = function (source, params) {
    var _toString = function (obj, format) {
        var ctor = function (o) {
            if (typeof o == 'number')
                return Number;
            else if (typeof o == 'boolean')
                return Boolean;
            else if (typeof o == 'string')
                return String;
                return o.constructor;
        } (obj);
        var proto = ctor.prototype;
        var formatter = typeof obj != 'string' ? proto ? proto.format || proto.toString : obj.format || obj.toString : obj.toString;
        if (formatter)
            if (typeof format == 'undefined' || format == "")
                return, format);
            return "";
    if (arguments.length == 1)
        return function () {
            return String.format.apply(null, [source].concat(, 0)));
    if (arguments.length == 2 && typeof params != 'object' && typeof params != 'array')
        params = [params];
    if (arguments.length > 2)
        params =, 1);
    source = source.replace(/\{\{|\}\}|\{([^}: ]+?)(?::([^}]*?))?\}/g, function (match, num, format) {
        if (match == "{{") return "{";
        if (match == "}}") return "}";
        if (typeof params[num] != 'undefined' && params[num] !== null) {
            return _toString(params[num], format);
        } else {
            return "";
    return source;
This question has already been answered. Start a new discussion instead.