javascript - Ajax request Error 404 -


hello again , in advance. let me first show code , problem trying resolve:

<span class='dropdown' id='status'>               <?php                 switch ($status) {                   case "unassigned":                   echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $status . "<span class='caret'></span></button>";                   echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";                   echo "<li><a class='editstatus' href='pending'>pending</a></li>";                   echo "</ul>";                   break;                    case "pending":                   echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $status . "<span class='caret'></span></button>";                   echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";                   echo "<li><a class='editstatus' href='attending'>attending</a></li>";                   echo "<li><a class='editstatus' href='followup'>follow up</a></li>";                   echo "<li><a class='editstatus' href='closed'>closed</a></li>";                   echo "</ul>";                   break;                    case "attending":                   echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $status . "<span class='caret'></span></button>";                   echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";                   echo "<li><a class='editstatus' href='pending'>pending</a></li>";                   echo "<li><a class='editstatus' href='followup'>follow up</a></li>";                   echo "<li><a class='editstatus' href='closed'>closed</a></li>";                   echo "</ul>";                   break;                    case "followup":                   echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $status . "<span class='caret'></span></button>";                   echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";                   echo "<li><a class='editstatus' href='closed'>closed</a></li>";                   echo "</ul>";                   break;                    case "closed":                   echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $status . "<span class='caret'></span></button>";                   echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";                   echo "<li><a class='editstatus' href='pending'>pending</a></li>";                   echo "<li><a class='editstatus' href='attending'>attending</a></li>";                   echo "<li><a class='editstatus' href='followup'>follow up</a></li>";                   echo "</ul>";                   break;                 }               ?>                           </span>  

i have span in php script includes dropdown button options represent different status of message being displayed in page, , through ajax send info php script

<script> var phpvar1 = "<?php echo $frompost_id_sanitized; ?>"; var phpvar = "<?php echo $status; ?>";  $('a.editstatus').click(function(event) { event.preventdefault();     var statusjs = $(this).attr("href");      alert('change status of ticket to: ' + statusjs)     $.post('ajaxchangestatus.php', {status: statusjs, id: phpvar1, initialstatus: phpvar}, function(data) {         $('#status').html(data)     }); }); 

finally 2nd php script adds data db , sends html 1st php script (some code omitted)

switch ($frompost_status_sanitized) {     case "pending":     echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $frompost_status_sanitized . "&nbsp;<span class='caret'></span></button>";     echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";     echo "<li><a class='editstatus' href='attending'>attending</a></li>";     echo "<li><a class='editstatus' href='followup'>follow up</a></li>";     echo "<li><a class='editstatus' href='closed'>closed</a></li>";     echo "</ul>";     break;      case "attending":     echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $frompost_status_sanitized . "&nbsp;<span class='caret'></span></button>";     echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";     echo "<li><a class='editstatus' href='pending'>pending</a></li>";     echo "<li><a class='editstatus' href='followup'>follow up</a></li>";     echo "<li><a class='editstatus' href='closed'>closed</a></li>";     echo "</ul>";     break;      case "followup":     echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $frompost_status_sanitized . "&nbsp;<span class='caret'></span></button>";     echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";     echo "<li><a class='editstatus' href='closed'>closed</a></li>";     echo "</ul>";     break;      case "closed":     echo "<button type='button'  data-toggle='dropdown' id='edit' aria-haspopup='true' aria-expanded='true' class='btn btn-danger dropdown-toggle'> status: " . $frompost_status_sanitized . "&nbsp;<span class='caret'></span></button>";     echo "<ul class='dropdown-menu'   aria-labelledby='edit'>";     echo "<li><a class='editstatus' href='pending'>pending</a></li>";     echo "<li><a class='editstatus' href='attending'>attending</a></li>";     echo "<li><a class='editstatus' href='followup'>follow up</a></li>";     echo "</ul>";     break; } 

everything seems works ok:

the idea have (in 1st php script) dropdown button options(representing status of message displayed). when option(eg status changed) selected(click event) send through ajax 2nd php script option selected(the new status), perform actions , return appropriate html (dropdown button different oprions) 1st php script.

the problem if select option (eg if try change status again without reloading page) 404 error, because when click in option instead of having click event triggered , event.preventdefault ......(as should happen), app reads href attribute[which used sending data 2nd php script this: var statusjs = $(this).attr("href");] , tries load page causes 404 error http://localhost:8888/ticketing/pending

normally js script should read value href attribute, prevent default action(eg load page causes 404), send data 2nd php script , replace span contants html returned

what wrong?

delegation solution

https://learn.jquery.com/events/event-delegation/

thanks lot


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -