Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I pass an Id to a new page in ajax
    primarykey
    data
    text
    <p>Javascript for getting the review by its ID all of the javascript can be accessed here <a href="http://creative.coventry.ac.uk/~4078078/client4/get.js" rel="nofollow">here</a></p> <pre><code>//get a review by id function Getreviewid(id){ $.ajax({ url: 'http://creative.coventry.ac.uk/~4078078/moviereviews/v1.0/index.php/review/reviewid/'+id, dataType: 'json', success: function(data) { console.log(id); $("#reviewdetail").empty(); $('#reviewdetail').append('&lt;img src='+data.review.image+' style="width:150px; height:150px" , onerror="imgError(this);"&lt;/img&gt;'); $('#reviewdetail').append('&lt;p&gt;&lt;b&gt;Title: &lt;/b&gt;'+data.review.Title+'&lt;/p&gt;'); $('#reviewdetail').append('&lt;p&gt;&lt;b&gt;Publisher: &lt;/b&gt; '+data.review.publisher+'&lt;/p&gt;'); $('#reviewdetail').append('&lt;p&gt;&lt;b&gt;Review: &lt;/b&gt; '+data.review.review+'&lt;/p&gt;'); // $('#reviewdetails').append('&lt;a href="#updatereview" id="editreview" onclick="updatereview('+review.id+');" data-role="button" data-mini="true" data-inline="true"&gt;Edit&lt;/a&gt;'); $.mobile.changePage("#detailreview"); //show the results page }, error: function (response) { var r = jQuery.parseJSON(response.responseText); alert("Message: " +r.error.text); } function updateReviewForm(){ id =$("#review-id").text(); $("#r_id").val = id; } </code></pre> <p>function updatereview(id){</p> <pre><code>$.ajax({ type:'post', url: 'http://creative.coventry.ac.uk/~4078078/moviereviews/v1.0/index.php/review/updatereview/'+id, headers: {authorization:readCookie('cookie')}, //use the cookie for authentication data: { title:$("#updatetitle").val(), review:$("#updatereviewwrite").val(), publisher:$("#updatepublisher").val(), username:$("#updateusername").val(),}, //rating:$("#rating-1").val() dataType: 'json', success: function(data) { alert("Review Updated. Please continue."); $("#updatetitle").val(''); //clear the text boxes $("#updatereviewwrite").val(''); $("#updateusername").val(''); $("#updatepublisher").val(''); //$("#rating-1").val(''); Getreviewid(reviewsisbn); }, error: function (response) { var r = jQuery.parseJSON(response.responseText); console.log(r); alert("Error:" + r.error.text); } }); </code></pre> <p>}</p> <p>HTML CODE FOR UPDATE FORM:</p> <pre><code>&lt;!--update review--&gt; &lt;div data-role="page" id="updatereview" data-theme="a"&gt; &lt;div data-theme="a" data-role="header"&gt; &lt;a data-role="button" data-mini="true" data-rel="back" data-theme="a" data-icon="back" data-iconpos="notext" data-transition="slide"&gt;&lt;/a&gt; &lt;h3 class="pagetitle"&gt; Write a Review &lt;/h3&gt; &lt;/div&gt; &lt;div data-role="content"&gt; &lt;h3&gt;Update a Review&lt;/h3&gt; &lt;fieldset&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="updatetitle"&gt;Title:&lt;/label&gt; &lt;textarea type="text" value="" name="updateTitle" id="updatetitle"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="updatereviewwrite"&gt;Review:&lt;/label&gt; &lt;textarea type="text" value="" name="updatereviewwrite" id="updatereviewwrite"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="updatepublisher"&gt;Publisher:&lt;/label&gt; &lt;textarea type="text" value="" name="updatepublisher" id="updatepublisher"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div data-role="fieldcontain"&gt; &lt;label for="updateusername"&gt;Username:&lt;/label&gt; &lt;textarea type="text" value="" name="updateusername" id="updateusername"&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;!-- &lt;div id="rating"&gt;&lt;/div&gt; &lt;br /&gt; Your Rating: &lt;span id="rating-1"&gt;not set&lt;/span&gt;--&gt; &lt;input type="hidden" value="" id="r_id" name="r_id"&gt; &lt;input type="button" data-theme="a" name="submit" onclick="updatereview()" value="Submit" &gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>html code for the page that is displaying the review details</p> <pre><code> &lt;!--detail Reviews example page--&gt; &lt;div data-role="page" id="detailreview" data-theme="a"&gt; &lt;div data-theme="a" data-role="header"&gt; &lt;a data-role="button" data-mini="true" data-rel="back" data-theme="a" data-icon="back" data-iconpos="notext" data-transition="slide"&gt;&lt;/a&gt; &lt;h3 class="pagetitle"&gt; Reviews &lt;/h3&gt; &lt;/div&gt; &lt;div data-role="content"&gt; &lt;div id="reviewdetail"&gt; &lt;!--get review details--&gt; &lt;/div&gt; &lt;a data-role="button" id="editreview" href="#updatereview" onclick="updateReviewForm()" data-mini="true" data-theme="a" data-icon="edit" data-transition="slide"&gt;Edit&lt;/a&gt; &lt;div data-theme="a" data-role="navbar" data-iconpos="bottom" data-position="fixed" &gt; &lt;ul&gt; &lt;li&gt; &lt;a href="#home" data-transition="slide" data-theme="a" data-icon="home" &gt; Home&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a onclick="Getreviewmovies()" data-transition="slide" data-theme="a" data-icon="edit" &gt; Reviews &lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#contactus" data-rel="dialog" data-transition="pop" data-theme="a" data-icon="bars"&gt; Contact us &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>PHP code for updating the review is as follow</p> <pre><code>function updatereview_post($id=null){ { $headers = apache_request_headers(); { if (empty($headers['authorization'])) { $info-&gt;status = 'failure'; $info-&gt;error-&gt;code = 15; $info-&gt;error-&gt;text = 'basic HTTP AUTHENTICATION required'; $this-&gt;response($info, 401); } } $string = base64_decode($headers['authorization']); list($username, $password) = explode(':', $string); { $this-&gt;load-&gt;database(); $sql = 'SELECT COUNT(userid) AS records FROM users '.'WHERE authorization = "'.$headers['authorization'].'";'; $query = $this-&gt;db-&gt;query($sql); $data = $query-&gt;row(); if ($data-&gt;records == "0") { $info-&gt;status = 'failure'; $info-&gt;error-&gt;code = 19; $info-&gt;error-&gt;text = 'authorization string is not valid'; $this-&gt;response($info, 401); } }} { if (!isset($id)){// check if the ID is specified in the URI $info-&gt;status = 'failure'; $info-&gt;error-&gt;code = 11; $info-&gt;error-&gt;text = 'id not specified in URI'; $this-&gt;response($info, 400); }} { // if the resource exist $this-&gt;load-&gt;database(); $sql = 'SELECT COUNT(id) AS records FROM reviews WHERE id = '.$id.';'; //$this-&gt;response($sql, 200); $query = $this-&gt;db-&gt;query($sql); $data = $query-&gt;row(); if ($data-&gt;records == "0") { $info-&gt;status = 'failure'; $info-&gt;error-&gt;code = 12; $info-&gt;error-&gt;text = 'id does not exist or have a resource'; $this-&gt;response($info, 404); } } $this-&gt;load-&gt;database(); $sql= 'SELECT * FROM reviews WHERE id= "'.$id.'";'; $query= $this-&gt;db-&gt;query($sql); $data-&gt;old = $query-&gt;row(); $data-&gt;changes = $_POST; $this-&gt;db-&gt;where('id', $id); $this-&gt;db-&gt;set('reviews',$_POST); $data-&gt;rows = $this-&gt;db-&gt;affected_rows(); $query= $this-&gt;db-&gt;query($sql); $data-&gt;new = $query-&gt;row(); $this-&gt;response($data,200); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload