0

After submitting a form I'm directed to a blank page that shows some json data such as:

some error

{"status":0,"message":"some error message here"}

or success

{"status":1,"message":"You have been signed up!"}

I would like the contents of a span element to be replaced with the message from the json data.

span element:

<span class="ladda-label" id="notice">Get notified!</span>

My script is located after my jquery and is as follows

<script>
$(document).ready(function() {
  $.ajax({
  dataType: 'json',
  success: function( data ) {
    var prices = data.message;
    $('#notice').html(data.message);
 }
   });
 });
</script> 

I'm pretty confident I'm not doing a single thing correctly here.

4
  • I don't understand question, can you explain? Can you put other codes? Commented Oct 13, 2015 at 19:25
  • I would like the contents of a span element to be replaced with the message from the json data. Commented Oct 13, 2015 at 19:50
  • There aren't url and method in your Ajax request Commented Oct 14, 2015 at 5:47
  • You can write it as $().html(prices) Commented Oct 14, 2015 at 5:49

1 Answer 1

1

...be more carefull )

<script>
  $.ajax('/my-data-url',{
  dataType: 'json',
  success: function( data ) {
    var prices = data.message;

    //$('#notice').text -> html( message.data !!! -> data.message);

    $('#notice').html(data.message);
     },
  error: function() {
     console.log('connection error')
  }
  });
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

I'm still getting the white mage with just my json data (but you did get rid of my text editor warning. I've posted my current script

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.