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) { 


                }
        }); 
3
  • There's a lot of quotes and an equal sign in the object, is that what you intended to send ? Commented Feb 19, 2015 at 10:41
  • i want to send content : ( msisdn = variable already stored in my code ) Commented Feb 19, 2015 at 10:43
  • and type = GetCustomer Commented Feb 19, 2015 at 10:43

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

yes there is no error in ajax syntax , i had a problem in customer.php and i solve it , thank you :)
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) { 


            }
    }); 

1 Comment

No, not if they do not contain special characters. See this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.