0

please i need help in my ajax code, i have an error in sending the data in ajax. it give me an error in data syntax, i tried to change it many time and i did't success-ed

this is my code :

$.ajax({
        type: "POST",
        url: "customer.php",
        data: {content : '"msisdn = '+mob+'"' , type : 'GetCustomer' }, 
        dataType: "json",
                  success:function(data){
          alert(data);        
        },
         error: function(error) { 


                }
        }); 
Sereen star
  • 211
  • 2
  • 3
  • 8

2 Answers2

1

There is no syntax error in your data attribute (see http://jsfiddle.net/nwjrf0jy/).

If you view the page wit some debugging tool activated you can see the request to customer.php being made. In case of jfiddle it returns a 404 error.

My guess would be, your customer.php does not return valid JSON content. This includes setting the response headers to application/json.

And be aware that because of your additional double quotes your $_POST['content'] will be '"msisdn = 12345"'. Somehow I don't think you want that.

Jens
  • 2,050
  • 1
  • 14
  • 30
0

May be keys used in data object need to enclosed in quots.

$.ajax({
    type: "POST",
    url: "customer.php",
    data: {'content' : '"msisdn = '+mob+'"' , 'type' : 'GetCustomer' }, 
    dataType: "json",
              success:function(data){
      alert(data);        
    },
     error: function(error) { 


            }
    }); 
  • No, not if they do not contain special characters. See [this answer](http://stackoverflow.com/a/12992018/1625955). – Jens Feb 19 '15 at 10:58