views:

27

answers:

1

I've written the following code to get JSON data with a POST request.

    $.post("http://example.com/songs/search_api/index.php",
      "data[Song][keyword]=Stereophonics",
      function(data){
        /*$("#results").append(data);*/
        alert("test");

        var songdata = JSON.parse(data);

        //$("#results").empty();

        var i = 0;

        for (i=0;i<=songdata.total;i++)
        {
            //alert(i);

            var songhtml = "<ul><li><img src=\"" + songdata.data[i].artwork + "\" /></li><li>" + songdata.data[i].title + "</li><li>" + songdata.data[i].artist + "</li><li>" + songdata.data[i].length + "</li><li>" + songdata.data[i].listen + "</li></ul>";
            //alert(songhtml);
            $("#results").append(songhtml);

        }
        //var objectasstring = concatObject(songdata);
        //alert(objectasstring + "\n\n" + songdata);
      }
    );

The problem is as soon as I put in a function (this works without the above code) the function fails to run;

function postRequest() {

alert("hello??");

}

This is for mobile Safari on the iPhone.

Thanks in advance.

A: 

Solved! My problem? The form. I was using a form so the page was being refreshed when the function was run.



Ben