Can anyone tell what would be the correct syntax for data

var ev = $("#update").val();
    var up=$("#upload").val();



        $.ajax(
        {

            data: ______,

Recommended Answers

All 5 Replies

Generally its in json format. How you specify it depends on what the server side method is expecting.

For example:

 data: {key1: 'value1', key2: 'value2'}

You mean that the key1 is the field on my MySql table and the value is my id on the html form right?

Not necessarily, but it could be. Your .ajax method is sending data to a web service runing server side correct? Your server side script should be expecting certain parameters. These would be your keys. Yes, the values are coming from your form.

There are several examples on the jQuery site: https://api.jquery.com/jQuery.ajax/

this is my form

<textarea name="update_event" id="update_event"  ></textarea>
            <form id="imageform_event" method="post" enctype="multipart/form-data" action='announce_event.php'> 
            <div id='preview_event'>
            </div>
            <div id='imageloadstatus'>
                <img src='<?php echo $base_url;?>wall_icons/ajaxloader.gif'/> Uploading please wait ....
            </div>
            <div id='imageloadbutton' class="wall">
                <span id='addphoto'><b>Add Photo:</b></span> <input type="file" name="photoimg_event" id="photoimg_event" />
            </div>
            <div>title:
            <input type="text" id='title_event' />
            </div>
            </form><br>
           <input align="middle" type="submit" class="event_button AudioSearchButton" align="middle" name="event_button" id="event_button" value="Share">

and this the ajax. The problem is that the button doesn't do anynothing

$(".event_button").click(function() 
{
    var updateval = $("#update_event").val();
    var uploadvalues=$("#photoimg_event").val();
    var title=$("#title_event").val();


    var dataString = 'description='+ updateval+'&image_path='+uploadvalues+'&title='+ title+'&image_path='+uploadvalues;
    if($.trim(updateval).length==0)
    {
        alert("Please Enter Some Text");
    }
    else
    {
        $("#flash").show();
        $("#flash").fadeIn(400).html('Loading Update...');
        $.ajax(
        {
            type: "POST",
            url: "message_ajax.php",
            data: dataString,
            cache: false,
            success: function(html)
            {
                $("#webcam_container").slideUp('fast');
                $("#flash").fadeOut('slow');
                $("#content").prepend(html);
                $("#update_event").val('').focus().css("height", "40px");   
                $('#preview_event').html('');
                $('#photoimg_event').val('');
                var c=$('#update_count').html();
                $('#update_count').html(parseInt(c)+1);
            }
        });
        $("#preview_event").html();
        $('#imageupload').slideUp('fast');
    }
    return false;
});
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.